mstorsjo created this revision.
mstorsjo added reviewers: MaskRay, nickdesaulniers, raj.khem.
Herald added a subscriber: kristof.beyls.
mstorsjo requested review of this revision.
Herald added a project: clang.
If multiple instances of the -arm-implicit-it option is passed to
the backend, it errors out.
Also fix cases where there are multiple -Wa,-mimplicit-it; the existing
tests indicate that the last one specified takes effect, while in
practice it passed double options, which didn't work as intended.
This goes on top of a reverted 2919222d8017f2425a85765b95e4b7c6f8e70ca4
<https://reviews.llvm.org/rG2919222d8017f2425a85765b95e4b7c6f8e70ca4>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102812
Files:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/arm-target-as-mimplicit-it.s
Index: clang/test/Driver/arm-target-as-mimplicit-it.s
===================================================================
--- clang/test/Driver/arm-target-as-mimplicit-it.s
+++ clang/test/Driver/arm-target-as-mimplicit-it.s
@@ -10,22 +10,22 @@
// RUN: %clang -target arm-linux-gnueabi -### -Xassembler -mimplicit-it=arm %s 2>&1 | FileCheck %s --check-prefix=ARM
// RUN: %clang -target arm-linux-gnueabi -### -Xassembler -mimplicit-it=thumb %s 2>&1 | FileCheck %s --check-prefix=THUMB
/// Test space separated -Wa,- arguments (latter wins).
+// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always -Wa,-mimplicit-it=always %s 2>&1 | FileCheck %s --check-prefix=ALWAYS
// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=never -Wa,-mimplicit-it=always %s 2>&1 | FileCheck %s --check-prefix=ALWAYS
// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always -Wa,-mimplicit-it=never %s 2>&1 | FileCheck %s --check-prefix=NEVER
// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always -Wa,-mimplicit-it=arm %s 2>&1 | FileCheck %s --check-prefix=ARM
// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always -Wa,-mimplicit-it=thumb %s 2>&1 | FileCheck %s --check-prefix=THUMB
/// Test comma separated -Wa,- arguments (latter wins).
+// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=always %s 2>&1 | FileCheck %s --check-prefix=ALWAYS
// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=never,-mimplicit-it=always %s 2>&1 | FileCheck %s --check-prefix=ALWAYS
// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=never %s 2>&1 | FileCheck %s --check-prefix=NEVER
// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=arm %s 2>&1 | FileCheck %s --check-prefix=ARM
// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=thumb %s 2>&1 | FileCheck %s --check-prefix=THUMB
-/// Mix -implicit-it= (compiler) with -Wa,-mimplicit-it= (assembler), assembler
-/// takes priority. -mllvm -arm-implicit-it= will be repeated, with the
-/// assembler flag appearing last (latter wins).
-// RUN: %clang -target arm-linux-gnueabi -### -mimplicit-it=never -Wa,-mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=NEVER_ALWAYS
-// RUN: %clang -target arm-linux-gnueabi -### -mimplicit-it=always -Wa,-mimplicit-it=never %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=ALWAYS_NEVER
-// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=never -mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=ALWAYS_NEVER
+/// Mix -implicit-it= (compiler) with -Wa,-mimplicit-it= (assembler). If
+/// they match, emit only one argument, if mismatch, error out.
+// RUN: %clang -target arm-linux-gnueabi -### -mimplicit-it=always -Wa,-mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=ALWAYS
+// RUN: %clang -target arm-linux-gnueabi -### -mimplicit-it=never -Wa,-mimplicit-it=always %S/Inputs/wildcard1.c 2>&1 | FileCheck %s --check-prefix=MISMATCH
/// Test invalid input.
// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=foo %s 2>&1 | FileCheck %s --check-prefix=INVALID
@@ -34,11 +34,13 @@
// RUN: %clang -target arm-linux-gnueabi -### -Wa,-mimplicit-it=always,-mimplicit-it=foo %s 2>&1 | FileCheck %s --check-prefix=INVALID
+/// Check that there isn't a second -arm-implicit-it following the matched one.
// ALWAYS: "-mllvm" "-arm-implicit-it=always"
+// ALWAYS-NOT: "-arm-implicit-it={{.*}}"
// NEVER: "-mllvm" "-arm-implicit-it=never"
+// NEVER-NOT: "-arm-implicit-it={{.*}}"
// ARM: "-mllvm" "-arm-implicit-it=arm"
// THUMB: "-mllvm" "-arm-implicit-it=thumb"
-// NEVER_ALWAYS: "-mllvm" "-arm-implicit-it=never" "-mllvm" "-arm-implicit-it=always"
-// ALWAYS_NEVER: "-mllvm" "-arm-implicit-it=always" "-mllvm" "-arm-implicit-it=never"
+// MISMATCH: error: unsupported argument '{{.*}}' to option '-mimplicit-it'
// INVALID: error: unsupported argument '-mimplicit-it=foo' to option 'Wa,'
// XINVALID: error: unsupported argument '-mimplicit-it=foo' to option 'Xassembler'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2366,15 +2366,15 @@
DumpCompilationDatabase(C, "", Target, Output, Input, Args);
}
-static bool AddARMImplicitITArgs(const ArgList &Args, ArgStringList &CmdArgs,
+static bool CheckARMImplicitITArg(StringRef Value) {
+ return Value == "always" || Value == "never" || Value == "arm" ||
+ Value == "thumb";
+}
+
+static void AddARMImplicitITArgs(const ArgList &Args, ArgStringList &CmdArgs,
StringRef Value) {
- if (Value == "always" || Value == "never" || Value == "arm" ||
- Value == "thumb") {
- CmdArgs.push_back("-mllvm");
- CmdArgs.push_back(Args.MakeArgString("-arm-implicit-it=" + Value));
- return true;
- }
- return false;
+ CmdArgs.push_back("-mllvm");
+ CmdArgs.push_back(Args.MakeArgString("-arm-implicit-it=" + Value));
}
static void CollectArgsForIntegratedAssembler(Compilation &C,
@@ -2393,16 +2393,17 @@
DefaultIncrementalLinkerCompatible))
CmdArgs.push_back("-mincremental-linker-compatible");
+ StringRef ImplicitItCompiler;
switch (C.getDefaultToolChain().getArch()) {
case llvm::Triple::arm:
case llvm::Triple::armeb:
case llvm::Triple::thumb:
case llvm::Triple::thumbeb:
if (Arg *A = Args.getLastArg(options::OPT_mimplicit_it_EQ)) {
- StringRef Value = A->getValue();
- if (!AddARMImplicitITArgs(Args, CmdArgs, Value))
+ ImplicitItCompiler = A->getValue();
+ if (!CheckARMImplicitITArg(ImplicitItCompiler))
D.Diag(diag::err_drv_unsupported_option_argument)
- << A->getOption().getName() << Value;
+ << A->getOption().getName() << ImplicitItCompiler;
}
break;
default:
@@ -2422,6 +2423,7 @@
bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
bool UseNoExecStack = C.getDefaultToolChain().isNoExecStackDefault();
const char *MipsTargetFeature = nullptr;
+ StringRef ImplicitItAsm;
for (const Arg *A :
Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
A->claim();
@@ -2444,9 +2446,12 @@
case llvm::Triple::thumbeb:
case llvm::Triple::arm:
case llvm::Triple::armeb:
- if (Value.startswith("-mimplicit-it=") &&
- AddARMImplicitITArgs(Args, CmdArgs, Value.split("=").second))
- continue;
+ if (Value.startswith("-mimplicit-it=")) {
+ // Only store the value; the last invocation takes effect.
+ ImplicitItAsm = Value.split("=").second;
+ if (CheckARMImplicitITArg(ImplicitItAsm))
+ continue;
+ }
if (Value == "-mthumb")
// -mthumb has already been processed in ComputeLLVMTriple()
// recognize but skip over here.
@@ -2576,6 +2581,20 @@
}
}
}
+ if (!ImplicitItCompiler.empty() && !ImplicitItAsm.empty()) {
+ // Set both via compiler flag and asm flag; ok if they match.
+ if (ImplicitItCompiler == ImplicitItAsm)
+ AddARMImplicitITArgs(Args, CmdArgs, ImplicitItAsm);
+ else {
+ std::string Values = (ImplicitItCompiler + " and " + ImplicitItAsm).str();
+ D.Diag(diag::err_drv_unsupported_option_argument)
+ << "-mimplicit-it" << Values;
+ }
+ } else if (!ImplicitItCompiler.empty()) {
+ AddARMImplicitITArgs(Args, CmdArgs, ImplicitItCompiler);
+ } else if (!ImplicitItAsm.empty()) {
+ AddARMImplicitITArgs(Args, CmdArgs, ImplicitItAsm);
+ }
if (UseRelaxRelocations)
CmdArgs.push_back("--mrelax-relocations");
if (UseNoExecStack)
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits