[clang-tools-extra] 68fe067 - [clangd] Disable backend-releated filelist compiler options.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 4 04:04:56 PST 2023


Author: Haojian Wu
Date: 2023-01-04T13:00:24+01:00
New Revision: 68fe0674187d1b44058c916620a6babfa626c947

URL: https://github.com/llvm/llvm-project/commit/68fe0674187d1b44058c916620a6babfa626c947
DIFF: https://github.com/llvm/llvm-project/commit/68fe0674187d1b44058c916620a6babfa626c947.diff

LOG: [clangd] Disable backend-releated filelist compiler options.

These options doesn't affect the AST generation, and clang will crash
(CreateOrDie in ASTContext) immedidately when the provided file are not existed.

Disable them in clangd to make clangd more robust.

Differential Revision: https://reviews.llvm.org/D140960

Added: 
    

Modified: 
    clang-tools-extra/clangd/Compiler.cpp
    clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp
index 04ec04514eb97..f242db44b4317 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -80,6 +80,15 @@ void disableUnsupportedOptions(CompilerInvocation &CI) {
   CI.getFrontendOpts().PluginArgs.clear();
   CI.getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly;
   CI.getFrontendOpts().ActionName.clear();
+
+  // These options mostly affect codegen, and aren't relevant to clangd. And
+  // clang will die immediately when these files are not existed.
+  // Disable these uninteresting options to make clangd more robust.
+  CI.getLangOpts()->NoSanitizeFiles.clear();
+  CI.getLangOpts()->XRayAttrListFiles.clear();
+  CI.getLangOpts()->ProfileListFiles.clear();
+  CI.getLangOpts()->XRayAlwaysInstrumentFiles.clear();
+  CI.getLangOpts()->XRayNeverInstrumentFiles.clear();
 }
 
 std::unique_ptr<CompilerInvocation>

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index f3cfee0570fb6..7310a11dc632f 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -824,6 +824,19 @@ TEST(DiagnosticsTest, IgnoreVerify) {
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
 }
 
+TEST(DiagnosticTest, IgnoreBEFilelistOptions) {
+  auto TU = TestTU::withCode("");
+  TU.ExtraArgs.push_back("-Xclang");
+  for (const auto *DisableOption :
+       {"-fsanitize-ignorelist=null", "-fprofile-list=null",
+        "-fxray-always-instrument=null", "-fxray-never-instrument=null",
+        "-fxray-attr-list=null"}) {
+    TU.ExtraArgs.push_back(DisableOption);
+    EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
+    TU.ExtraArgs.pop_back();
+  }
+}
+
 // Recursive main-file include is diagnosed, and doesn't crash.
 TEST(DiagnosticsTest, RecursivePreamble) {
   auto TU = TestTU::withCode(R"cpp(


        


More information about the cfe-commits mailing list