Skip to content

Commit 812e049

Browse files
committed
[Driver] Correctly handle -Wa,--crel -Wa,--no-crel
Follow-up to #97378
1 parent 26670e7 commit 812e049

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,8 +1143,8 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
11431143
addMachineOutlinerArgs(D, Args, CmdArgs, ToolChain.getEffectiveTriple(),
11441144
/*IsLTO=*/true, PluginOptPrefix);
11451145

1146+
bool Crel = false;
11461147
for (const Arg *A : Args.filtered(options::OPT_Wa_COMMA)) {
1147-
bool Crel = false;
11481148
for (StringRef V : A->getValues()) {
11491149
if (V == "--crel")
11501150
Crel = true;
@@ -1154,13 +1154,13 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
11541154
continue;
11551155
A->claim();
11561156
}
1157-
if (Crel) {
1158-
if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) {
1159-
CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + "-crel"));
1160-
} else {
1161-
D.Diag(diag::err_drv_unsupported_opt_for_target)
1162-
<< "-Wa,--crel" << D.getTargetTriple();
1163-
}
1157+
}
1158+
if (Crel) {
1159+
if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) {
1160+
CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + "-crel"));
1161+
} else {
1162+
D.Diag(diag::err_drv_unsupported_opt_for_target)
1163+
<< "-Wa,--crel" << D.getTargetTriple();
11641164
}
11651165
}
11661166
}

clang/test/Driver/crel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424

2525
/// The --allow-experimental-crel error check doesn't apply to LTO.
2626
// RUN: %clang -### --target=x86_64-linux -Werror -flto -Wa,--crel %s 2>&1 | FileCheck %s --check-prefix=LTO
27+
// RUN: %clang -### --target=x86_64-linux -Werror -flto -Wa,--crel -Wa,--no-crel %s 2>&1 | FileCheck %s --check-prefix=LTO-NO
2728

2829
// LTO: "-plugin-opt=-crel"
30+
// LTO-NO-NOT: "-plugin-opt=-crel"
2931

3032
// RUN: touch %t.o
3133
// RUN: not %clang -### --target=mips64-linux-gnu -flto -Wa,--crel %t.o 2>&1 | FileCheck %s --check-prefix=ERR

0 commit comments

Comments
 (0)