[lldb] Don't crash when the ASTImporter produces diagnostics but instead log them.
authorRaphael Isemann <teemperor@gmail.com>
Wed, 9 Oct 2019 08:30:06 +0000 (08:30 +0000)
committerRaphael Isemann <teemperor@gmail.com>
Wed, 9 Oct 2019 08:30:06 +0000 (08:30 +0000)
commit4e969da33e113dffc1dfcf5c5e3ef97e3b594161
treed41e04abc0116f6878ac4b4f1603b8e3f35afa52
parente9c8f6fea6d6c7a18ce97768c4b457e85421d10c
[lldb] Don't crash when the ASTImporter produces diagnostics but instead log them.

When playing with the C++ module prototype I noticed I can get LLDB to crash
by making a result type that depends on __make_integer_seq (a BuiltinTemplate)
which is not supported by the ASTImporter yet. This causes the ASTImporter to emit
a diagnostic when copying the type to the ScratchASTContext. As deporting the result
type is done after we are done parsing and the Clang's diagnostic engine asserts that
it can only be used during parsing, it crashes LLDB while trying to render the diagnostic
in the HandleDiagnostic method of ClangDiagnosticManagerAdapter.

This patch just moves the HandleDiagnostic call to Clang behind our check that we still
have a DiagnosticManager (which we remove after parsing) which prevents the assert
from firing. We also shouldn't ignore such diagnostics, so I added a log statement for
them.

There doesn't seem to way to test this as these diagnostic only happen when we copy
a node that's not supported by the ASTImporter which should never happen once
we can copy everything with the ASTImporter, so every test case we add here will
eventually become invalid.

(Note that most of this diff is just whitespace changes as we now use an early exit
instead of a huge 'if' block).

llvm-svn: 374145
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp