Author: nico Date: Wed Jul 10 15:29:35 2019 New Revision: 365703 URL: http://llvm.org/viewvc/llvm-project?rev=365703&view=rev Log: 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 Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/test/Driver/as-options.s Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=365703&r1=365702&r2=365703&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Jul 10 15:29:35 2019 @@ -3545,6 +3545,18 @@ void Clang::ConstructJob(Compilation &C, // Select the appropriate action. RewriteKind rewriteKind = RK_None; + // If CollectArgsForIntegratedAssembler() isn't called below, call it here + // with a dummy args list to mark assembler flags as used even when not + // running an assembler. Otherwise, clang would emit "argument unused" + // warnings for assembler flags when e.g. adding "-E" to flags while debugging + // something. That'd be somewhat inconvenient, and it's also inconsistent with + // most other flags -- we don't warn on -ffunction-sections not being used + // in -E mode either for example, even though it's not really used either. + if (!isa<AssembleJobAction>(JA)) { + ArgStringList DummyArgs; + CollectArgsForIntegratedAssembler(C, Args, DummyArgs, D); + } + if (isa<AnalyzeJobAction>(JA)) { assert(JA.getType() == types::TY_Plist && "Invalid output type."); CmdArgs.push_back("-analyze"); Modified: cfe/trunk/test/Driver/as-options.s URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/as-options.s?rev=365703&r1=365702&r2=365703&view=diff ============================================================================== --- cfe/trunk/test/Driver/as-options.s (original) +++ cfe/trunk/test/Driver/as-options.s Wed Jul 10 15:29:35 2019 @@ -35,3 +35,14 @@ // RUN: | FileCheck %s // CHECK: "-I" "foo_dir" + +// Test that assembler options don't cause warnings when there's no assembler +// stage. + +// RUN: %clang -mincremental-linker-compatible -E -o /dev/null %s 2>&1 \ +// RUN: | FileCheck --check-prefix=WARN --allow-empty %s +// RUN: %clang -mimplicit-it=always -target armv7-linux-gnueabihf -E %s \ +// RUN: | FileCheck --check-prefix=WARN --allow-empty %s +// RUN: %clang -Wa,-mbig-obj -target i386-pc-windows -E %s \ +// RUN: | FileCheck --check-prefix=WARN --allow-empty %s +// WARN-NOT: unused _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits