forked from OSchip/llvm-project
driver: Don't warn about assembler flags being unused when not assembling; different approach
This morally relands r365703 (and r365714), originally reviewed at https://reviews.llvm.org/D64527, but with a different implementation. Relanding the same approach with a fix for the revert reason got a bit involved (see https://reviews.llvm.org/D65108) so use a simpler approach with a more localized implementation (that in return duplicates code a bit more). This approach also doesn't validate flags for the integrated assembler if the assembler step doesn't run. Fixes PR42066. Differential Revision: https://reviews.llvm.org/D65233 llvm-svn: 367165
This commit is contained in:
parent
7bc4fad0fb
commit
b28ffd8f35
|
@ -2079,6 +2079,9 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
|
|||
break;
|
||||
}
|
||||
|
||||
// If you add more args here, also add them to the block below that
|
||||
// starts with "// If CollectArgsForIntegratedAssembler() isn't called below".
|
||||
|
||||
// When passing -I arguments to the assembler we sometimes need to
|
||||
// unconditionally take the next argument. For example, when parsing
|
||||
// '-Wa,-I -Wa,foo' we need to accept the -Wa,foo arg after seeing the
|
||||
|
@ -3543,6 +3546,35 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
// Select the appropriate action.
|
||||
RewriteKind rewriteKind = RK_None;
|
||||
|
||||
// If CollectArgsForIntegratedAssembler() isn't called below, claim the args
|
||||
// it claims 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)) {
|
||||
// The args claimed here should match the args used in
|
||||
// CollectArgsForIntegratedAssembler().
|
||||
if (TC.useIntegratedAs()) {
|
||||
Args.ClaimAllArgs(options::OPT_mrelax_all);
|
||||
Args.ClaimAllArgs(options::OPT_mno_relax_all);
|
||||
Args.ClaimAllArgs(options::OPT_mincremental_linker_compatible);
|
||||
Args.ClaimAllArgs(options::OPT_mno_incremental_linker_compatible);
|
||||
switch (C.getDefaultToolChain().getArch()) {
|
||||
case llvm::Triple::arm:
|
||||
case llvm::Triple::armeb:
|
||||
case llvm::Triple::thumb:
|
||||
case llvm::Triple::thumbeb:
|
||||
Args.ClaimAllArgs(options::OPT_mimplicit_it_EQ);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Args.ClaimAllArgs(options::OPT_Wa_COMMA);
|
||||
Args.ClaimAllArgs(options::OPT_Xassembler);
|
||||
}
|
||||
|
||||
if (isa<AnalyzeJobAction>(JA)) {
|
||||
assert(JA.getType() == types::TY_Plist && "Invalid output type.");
|
||||
CmdArgs.push_back("-analyze");
|
||||
|
|
|
@ -35,3 +35,51 @@
|
|||
// 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 \
|
||||
// RUN: -o /dev/null -x c++ %s 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOWARN --allow-empty %s
|
||||
// RUN: %clang -mincremental-linker-compatible -E \
|
||||
// RUN: -o /dev/null -x assembler-with-cpp %s 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOWARN --allow-empty %s
|
||||
// RUN: %clang -mimplicit-it=always -target armv7-linux-gnueabi -E \
|
||||
// RUN: -o /dev/null -x c++ %s 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOWARN --allow-empty %s
|
||||
// RUN: %clang -mimplicit-it=always -target armv7-linux-gnueabi -E \
|
||||
// RUN: -o /dev/null -x assembler-with-cpp %s 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOWARN --allow-empty %s
|
||||
// RUN: %clang -Wa,-mbig-obj -target i386-pc-windows -E \
|
||||
// RUN: -o /dev/null -x c++ %s 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOWARN --allow-empty %s
|
||||
// RUN: %clang -Wa,-mbig-obj -target i386-pc-windows -E \
|
||||
// RUN: -o /dev/null -x assembler-with-cpp %s 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOWARN --allow-empty %s
|
||||
// RUN: %clang -Xassembler -mbig-obj -target i386-pc-windows -E \
|
||||
// RUN: -o /dev/null -x c++ %s 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOWARN --allow-empty %s
|
||||
// RUN: %clang -Xassembler -mbig-obj -target i386-pc-windows -E \
|
||||
// RUN: -o /dev/null -x assembler-with-cpp %s 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOWARN --allow-empty %s
|
||||
// NOWARN-NOT: unused
|
||||
|
||||
// Test that unsupported arguments do not cause errors when -fno-integrated-as
|
||||
// is set.
|
||||
// RUN: %clang -Wa,-mno-warn-deprecated -fno-integrated-as %s -S 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOERROR --allow-empty %s
|
||||
// NOERROR-NOT: error: unsupported argument '-mno-warn-deprecated' to option 'Wa,'
|
||||
|
||||
// -Wa flags shouldn't cause warnings without an assembler stage with
|
||||
// -fno-integrated-as either.
|
||||
// RUN: %clang -Wa,-mno-warn-deprecated -fno-integrated-as %s -S 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOWARN --allow-empty %s
|
||||
|
||||
// But -m flags for the integrated assembler _should_ warn if the integrated
|
||||
// assembler is not in use.
|
||||
// RUN: %clang -mrelax-all -fintegrated-as %s -S 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=NOWARN --allow-empty %s
|
||||
// RUN: %clang -mrelax-all -fno-integrated-as %s -S 2>&1 \
|
||||
// RUN: | FileCheck --check-prefix=WARN --allow-empty %s
|
||||
// WARN: unused
|
||||
|
|
Loading…
Reference in New Issue