[clang-tools-extra] [clangd][modules] Remove the options that is for gcc, make modules work for clangd when using gcc (PR #200001)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 5 05:49:47 PDT 2026


https://github.com/Decodetalkers updated https://github.com/llvm/llvm-project/pull/200001

>From 0797be922aa6440df15d59c9db34555ca74b4671 Mon Sep 17 00:00:00 2001
From: ShootingStarDragons <ShootingStarDragons at protonmail.com>
Date: Fri, 5 Jun 2026 21:48:39 +0900
Subject: [PATCH] feat: remove unsupported compile options when driver detects
 them

and log the unsupported options to the editor
---
 clang-tools-extra/clangd/CompileCommands.cpp | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/clang-tools-extra/clangd/CompileCommands.cpp b/clang-tools-extra/clangd/CompileCommands.cpp
index 4eda330716f21..969bed097a3e4 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -273,6 +273,18 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
       SawInput(Cmd[I]);
     Cmd.resize(DashDashIndex);
   }
+
+  std::string UnsupportedArguments;
+  for (auto *UnknownArg : ArgList.filtered(options::OPT_UNKNOWN)) {
+    unsigned Index = UnknownArg->getIndex();
+    UnsupportedArguments += OriginalArgs[Index];
+    UnsupportedArguments += ", ";
+    IndicesToDrop.push_back(Index);
+  }
+  if (UnsupportedArguments.length() != 0) {
+    UnsupportedArguments.pop_back();
+    UnsupportedArguments.pop_back();
+  }
   llvm::sort(IndicesToDrop);
   for (unsigned Idx : llvm::reverse(IndicesToDrop))
     // +1 to account for the executable name in Cmd[0] that
@@ -327,6 +339,10 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
     return Elem.starts_with("--save-temps") || Elem.starts_with("-save-temps");
   });
 
+  if (UnsupportedArguments.length() != 0) {
+    log("Warning: detected unsupported Flags {0}", UnsupportedArguments);
+  }
+
   std::vector<std::string> ToAppend;
   if (ResourceDir && !HasExact("-resource-dir") && !HasPrefix("-resource-dir="))
     ToAppend.push_back(("-resource-dir=" + *ResourceDir));



More information about the cfe-commits mailing list