[llvm-branch-commits] [clang] 063556d - [clang(d)] Include/Exclude CLDXC options properly

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Sep 18 23:52:07 PDT 2022


Author: Kadir Cetinkaya
Date: 2022-09-19T08:51:44+02:00
New Revision: 063556d02def3637cdf7db4fe8650e7c4a1caca5

URL: https://github.com/llvm/llvm-project/commit/063556d02def3637cdf7db4fe8650e7c4a1caca5
DIFF: https://github.com/llvm/llvm-project/commit/063556d02def3637cdf7db4fe8650e7c4a1caca5.diff

LOG: [clang(d)] Include/Exclude CLDXC options properly

This handles the new CLDXC options that was introduced in
https://reviews.llvm.org/D128462 inside clang-tooling to make sure cl driver
mode is not broken.

Fixes https://github.com/clangd/clangd/issues/1292.

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

(cherry picked from commit 23ace26e0d1aa2283d65d192c37592fb0eef1b1f)

Added: 
    

Modified: 
    clang-tools-extra/clangd/CompileCommands.cpp
    clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
    clang/lib/Tooling/InterpolatingCompilationDatabase.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp b/clang-tools-extra/clangd/CompileCommands.cpp
index 12aa9dacc2dfe..8db57f234591d 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -220,10 +220,13 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd,
   ArgList = OptTable.ParseArgs(
       llvm::makeArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount,
       /*FlagsToInclude=*/
-      IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)
+      IsCLMode ? (driver::options::CLOption | driver::options::CoreOption |
+                  driver::options::CLDXCOption)
                : /*everything*/ 0,
       /*FlagsToExclude=*/driver::options::NoDriverOption |
-          (IsCLMode ? 0 : driver::options::CLOption));
+          (IsCLMode
+               ? 0
+               : (driver::options::CLOption | driver::options::CLDXCOption)));
 
   llvm::SmallVector<unsigned, 1> IndicesToDrop;
   // Having multiple architecture options (e.g. when building fat binaries)

diff  --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
index e8cbaa2bba32d..28ae6ea01e87a 100644
--- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -415,6 +415,19 @@ TEST(CommandMangler, EmptyArgs) {
   // Make sure we don't crash.
   Mangler.adjust(Args, "foo.cc");
 }
+
+TEST(CommandMangler, PathsAsPositional) {
+  const auto Mangler = CommandMangler::forTests();
+  std::vector<std::string> Args = {
+      "clang",
+      "--driver-mode=cl",
+      "-I",
+      "foo",
+  };
+  // Make sure we don't crash.
+  Mangler.adjust(Args, "a.cc");
+  EXPECT_THAT(Args, Contains("foo"));
+}
 } // namespace
 } // namespace clangd
 } // namespace clang

diff  --git a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
index 0143b5f8df6b6..655be20572b66 100644
--- a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -165,8 +165,8 @@ struct TransferableCommand {
       const unsigned OldPos = Pos;
       std::unique_ptr<llvm::opt::Arg> Arg(OptTable.ParseOneArg(
           ArgList, Pos,
-          /* Include */ ClangCLMode ? CoreOption | CLOption : 0,
-          /* Exclude */ ClangCLMode ? 0 : CLOption));
+          /* Include */ ClangCLMode ? CoreOption | CLOption | CLDXCOption : 0,
+          /* Exclude */ ClangCLMode ? 0 : CLOption | CLDXCOption));
 
       if (!Arg)
         continue;


        


More information about the llvm-branch-commits mailing list