r313760 - Put target deduced from executable name at the start of argument list
Serge Pavlov via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 20 08:22:27 PDT 2017
Author: sepavloff
Date: Wed Sep 20 08:22:27 2017
New Revision: 313760
URL: http://llvm.org/viewvc/llvm-project?rev=313760&view=rev
Log:
Put target deduced from executable name at the start of argument list
When clang is called as 'target-clang', put deduced target option at
the start of argument list so that option '--target=' specified in command
line could override it.
This change fixes PR34671.
Added:
cfe/trunk/test/Driver/target-override.c
Modified:
cfe/trunk/tools/driver/driver.cpp
Added: cfe/trunk/test/Driver/target-override.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/target-override.c?rev=313760&view=auto
==============================================================================
--- cfe/trunk/test/Driver/target-override.c (added)
+++ cfe/trunk/test/Driver/target-override.c Wed Sep 20 08:22:27 2017
@@ -0,0 +1,16 @@
+// REQUIRES: shell
+// REQUIRES: x86-registered-target
+
+// RUN: mkdir -p %T/testbin
+// RUN: [ ! -s %T/testbin/i386-clang ] || rm %T/testbin/i386-clang
+// RUN: ln -s %clang %T/testbin/i386-clang
+
+// Check if invocation of "foo-clang" adds option "-target foo".
+//
+// RUN: %T/testbin/i386-clang -c -no-canonical-prefixes %s -### 2>&1 | FileCheck -check-prefix CHECK-TG1 %s
+// CHECK-TG1: Target: i386
+
+// Check if invocation of "foo-clang -target bar" overrides option "-target foo".
+//
+// RUN: %T/testbin/i386-clang -c -no-canonical-prefixes -target x86_64 %s -### 2>&1 | FileCheck -check-prefix CHECK-TG2 %s
+// CHECK-TG2: Target: x86_64
Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=313760&r1=313759&r2=313760&view=diff
==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Wed Sep 20 08:22:27 2017
@@ -209,16 +209,23 @@ extern int cc1as_main(ArrayRef<const cha
static void insertTargetAndModeArgs(const ParsedClangName &NameParts,
SmallVectorImpl<const char *> &ArgVector,
std::set<std::string> &SavedStrings) {
+ // Put target and mode arguments at the start of argument list so that
+ // arguments specified in command line could override them. Avoid putting
+ // them at index 0, as an option like '-cc1' must remain the first.
+ auto InsertionPoint = ArgVector.begin();
+ if (InsertionPoint != ArgVector.end())
+ ++InsertionPoint;
+
if (NameParts.DriverMode) {
// Add the mode flag to the arguments.
- ArgVector.insert(ArgVector.end(),
+ ArgVector.insert(InsertionPoint,
GetStableCStr(SavedStrings, NameParts.DriverMode));
}
if (NameParts.TargetIsValid) {
const char *arr[] = {"-target", GetStableCStr(SavedStrings,
NameParts.TargetPrefix)};
- ArgVector.insert(ArgVector.end(), std::begin(arr), std::end(arr));
+ ArgVector.insert(InsertionPoint, std::begin(arr), std::end(arr));
}
}
More information about the cfe-commits
mailing list