[clang-tools-extra] 4457398 - [clangd] Don't crash on `#pragma clang __debug parser_crash`
Aleksandr Platonov via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 20 05:53:50 PDT 2020
Author: Aleksandr Platonov
Date: 2020-08-20T15:53:21+03:00
New Revision: 445739826567e5402b558f2c130d76dc916c82ec
URL: https://github.com/llvm/llvm-project/commit/445739826567e5402b558f2c130d76dc916c82ec
DIFF: https://github.com/llvm/llvm-project/commit/445739826567e5402b558f2c130d76dc916c82ec.diff
LOG: [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
Added:
Modified:
clang-tools-extra/clangd/Compiler.cpp
clang-tools-extra/clangd/unittests/CompilerTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp
index 2c7ef471d382..f5875e2a7971 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -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) {
diff --git a/clang-tools-extra/clangd/unittests/CompilerTests.cpp b/clang-tools-extra/clangd/unittests/CompilerTests.cpp
index 59feb9312d23..45e9bcd9d534 100644
--- a/clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -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
More information about the cfe-commits
mailing list