Skip to content

Commit 101c1af

Browse files
committed
driver: Don't warn about assembler flags being unused when not assembling
clang currently warns when passing flags for the assembler (e.g. -Wa,-mbig-obj) to an invocation that doesn't run the assembler (e.g. -E). At first sight, that makes sense -- the flag really is unused. But many other flags don't have an effect if no assembler runs (e.g. -fno-integrated-as, -ffunction-sections, and many others), and those currently don't warn. So this seems more like a side effect of how CollectArgsForIntegratedAssembler() is implemented than like an intentional feature. Since it's a bit inconvenient when debugging builds and adding -E, always call CollectArgsForIntegratedAssembler() to make sure assembler args always get claimed. Currently, this affects only these flags: -mincremental-linker-compatible, -mimplicit-it= (on ARM), -Wa, -Xassembler It does have the side effect that assembler options now need to be valid even if -E is passed. Previously, `-Wa,-mbig-obj` would error for non-coff output only if the assembler ran, now it always errors. This too makes assembler flags more consistent with all the other flags and seems like a progression. Fixes PR42066. Differential Revision: https://reviews.llvm.org/D64527 llvm-svn: 365703
1 parent d916f23 commit 101c1af

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,6 +3545,18 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
35453545
// Select the appropriate action.
35463546
RewriteKind rewriteKind = RK_None;
35473547

3548+
// If CollectArgsForIntegratedAssembler() isn't called below, call it here
3549+
// with a dummy args list to mark assembler flags as used even when not
3550+
// running an assembler. Otherwise, clang would emit "argument unused"
3551+
// warnings for assembler flags when e.g. adding "-E" to flags while debugging
3552+
// something. That'd be somewhat inconvenient, and it's also inconsistent with
3553+
// most other flags -- we don't warn on -ffunction-sections not being used
3554+
// in -E mode either for example, even though it's not really used either.
3555+
if (!isa<AssembleJobAction>(JA)) {
3556+
ArgStringList DummyArgs;
3557+
CollectArgsForIntegratedAssembler(C, Args, DummyArgs, D);
3558+
}
3559+
35483560
if (isa<AnalyzeJobAction>(JA)) {
35493561
assert(JA.getType() == types::TY_Plist && "Invalid output type.");
35503562
CmdArgs.push_back("-analyze");

clang/test/Driver/as-options.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,14 @@
3535
// RUN: | FileCheck %s
3636

3737
// CHECK: "-I" "foo_dir"
38+
39+
// Test that assembler options don't cause warnings when there's no assembler
40+
// stage.
41+
42+
// RUN: %clang -mincremental-linker-compatible -E -o /dev/null %s 2>&1 \
43+
// RUN: | FileCheck --check-prefix=WARN --allow-empty %s
44+
// RUN: %clang -mimplicit-it=always -target armv7-linux-gnueabihf -E %s \
45+
// RUN: | FileCheck --check-prefix=WARN --allow-empty %s
46+
// RUN: %clang -Wa,-mbig-obj -target i386-pc-windows -E %s \
47+
// RUN: | FileCheck --check-prefix=WARN --allow-empty %s
48+
// WARN-NOT: unused

0 commit comments

Comments
 (0)