[clangd] Don't crash on `#pragma clang __debug parser_crash`

Currently, clangd crashes when opening a file with `#pragma clang __debug parser_crash` (e.g. clang/test/Modules/Inputs/crash.h).
This patch disables these crashes.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D86279
This commit is contained in:
Aleksandr Platonov 2020-08-20 15:50:13 +03:00
parent 707138d677
commit 4457398265
2 changed files with 7 additions and 0 deletions

View File

@ -78,6 +78,8 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
CI->getPreprocessorOpts().PCHThroughHeader.clear();
CI->getPreprocessorOpts().PCHWithHdrStop = false;
CI->getPreprocessorOpts().PCHWithHdrStopCreate = false;
// Don't crash on `#pragma clang __debug parser_crash`
CI->getPreprocessorOpts().DisablePragmaDebugCrash = true;
// Recovery expression currently only works for C++.
if (CI->getLangOpts()->CPlusPlus) {

View File

@ -51,6 +51,11 @@ TEST(BuildCompilerInvocation, DropsPCH) {
IsEmpty());
}
TEST(BuildCompilerInvocation, PragmaDebugCrash) {
TestTU TU = TestTU::withCode("#pragma clang __debug parser_crash");
TU.build(); // no-crash
}
} // namespace
} // namespace clangd
} // namespace clang