[clang] 812e049 - [Driver] Correctly handle -Wa,--crel -Wa,--no-crel
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 15 17:32:21 PDT 2024
Author: Fangrui Song
Date: 2024-08-15T17:32:16-07:00
New Revision: 812e049ac1c2424f96746ac4c453d6255b0a6ca5
URL: https://github.com/llvm/llvm-project/commit/812e049ac1c2424f96746ac4c453d6255b0a6ca5
DIFF: https://github.com/llvm/llvm-project/commit/812e049ac1c2424f96746ac4c453d6255b0a6ca5.diff
LOG: [Driver] Correctly handle -Wa,--crel -Wa,--no-crel
Follow-up to #97378
Added:
Modified:
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/crel.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 1cba3e1220264..320d2901da06e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1143,8 +1143,8 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
addMachineOutlinerArgs(D, Args, CmdArgs, ToolChain.getEffectiveTriple(),
/*IsLTO=*/true, PluginOptPrefix);
+ bool Crel = false;
for (const Arg *A : Args.filtered(options::OPT_Wa_COMMA)) {
- bool Crel = false;
for (StringRef V : A->getValues()) {
if (V == "--crel")
Crel = true;
@@ -1154,13 +1154,13 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
continue;
A->claim();
}
- if (Crel) {
- if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) {
- CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + "-crel"));
- } else {
- D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-Wa,--crel" << D.getTargetTriple();
- }
+ }
+ if (Crel) {
+ if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) {
+ CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + "-crel"));
+ } else {
+ D.Diag(diag::err_drv_unsupported_opt_for_target)
+ << "-Wa,--crel" << D.getTargetTriple();
}
}
}
diff --git a/clang/test/Driver/crel.c b/clang/test/Driver/crel.c
index a47e7ebfeedd8..e1b3f58c6ea5b 100644
--- a/clang/test/Driver/crel.c
+++ b/clang/test/Driver/crel.c
@@ -24,8 +24,10 @@
/// The --allow-experimental-crel error check doesn't apply to LTO.
// RUN: %clang -### --target=x86_64-linux -Werror -flto -Wa,--crel %s 2>&1 | FileCheck %s --check-prefix=LTO
+// RUN: %clang -### --target=x86_64-linux -Werror -flto -Wa,--crel -Wa,--no-crel %s 2>&1 | FileCheck %s --check-prefix=LTO-NO
// LTO: "-plugin-opt=-crel"
+// LTO-NO-NOT: "-plugin-opt=-crel"
// RUN: touch %t.o
// RUN: not %clang -### --target=mips64-linux-gnu -flto -Wa,--crel %t.o 2>&1 | FileCheck %s --check-prefix=ERR
More information about the cfe-commits
mailing list