[clang] 73c00d4 - [clang][Driver] Pick the last --driver-mode in case of multiple ones

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 7 06:33:54 PDT 2021


Author: Kadir Cetinkaya
Date: 2021-09-07T15:33:45+02:00
New Revision: 73c00d40bd49ae022f6fbba7200f05facb533e3b

URL: https://github.com/llvm/llvm-project/commit/73c00d40bd49ae022f6fbba7200f05facb533e3b
DIFF: https://github.com/llvm/llvm-project/commit/73c00d40bd49ae022f6fbba7200f05facb533e3b.diff

LOG: [clang][Driver] Pick the last --driver-mode in case of multiple ones

This was an accidental behaviour change in D106789 and this patch
restores it back to original state.

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

Added: 
    

Modified: 
    clang/lib/Driver/Driver.cpp
    clang/unittests/Driver/ToolChainTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 4b56a97da717b..a92b6e8c0908b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5569,7 +5569,6 @@ llvm::StringRef clang::driver::getDriverMode(StringRef ProgName,
     if (!Arg.startswith(OptName))
       continue;
     Opt = Arg;
-    break;
   }
   if (Opt.empty())
     Opt = ToolChain::getTargetAndModeFromProgramName(ProgName).DriverMode;

diff  --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp
index 253c65d0e29fe..f117472957781 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -357,4 +358,10 @@ TEST(ToolChainTest, PostCallback) {
   EXPECT_TRUE(CallbackHasCalled);
 }
 
+TEST(GetDriverMode, PrefersLastDriverMode) {
+  static constexpr const char *Args[] = {"clang-cl", "--driver-mode=foo",
+                                         "--driver-mode=bar", "foo.cpp"};
+  EXPECT_EQ(getDriverMode(Args[0], llvm::makeArrayRef(Args).slice(1)), "bar");
+}
+
 } // end anonymous namespace.


        


More information about the cfe-commits mailing list