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

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 7 06:17:18 PDT 2021


kadircet created this revision.
kadircet added reviewers: hans, sammccall.
kadircet requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This was an accidental behaviour change in D106789 <https://reviews.llvm.org/D106789> and this patch
restores it back to original state.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109361

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


Index: clang/unittests/Driver/ToolChainTest.cpp
===================================================================
--- clang/unittests/Driver/ToolChainTest.cpp
+++ 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 @@
   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.
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5569,7 +5569,6 @@
     if (!Arg.startswith(OptName))
       continue;
     Opt = Arg;
-    break;
   }
   if (Opt.empty())
     Opt = ToolChain::getTargetAndModeFromProgramName(ProgName).DriverMode;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109361.371056.patch
Type: text/x-patch
Size: 1230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210907/5ff2ab04/attachment-0001.bin>


More information about the cfe-commits mailing list