Skip to content

Commit 9272aa9

Browse files
committed
[Driver] Do not generate error about unsupported target specific options when there is no compiler jobs
The upstream commit: https://reviews.llvm.org/D151590 added a new flag to mark target specific compiler options. The side effect of it was that in cases when -### or -v is used without any input file, clang started emitting an error. It happened like that becasue there is no compilation actions created which could consume/verify these target specific options. This patch changes that error to a warning about unused option in situations when there is no actions and still generates error when there are actions. Fix for #64958 Differential Revision: https://reviews.llvm.org/D159361
1 parent f8b04eb commit 9272aa9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4953,7 +4953,12 @@ void Driver::BuildJobs(Compilation &C) const {
49534953
// already been warned about.
49544954
if (!IsCLMode() || !A->getOption().matches(options::OPT_UNKNOWN)) {
49554955
if (A->getOption().hasFlag(options::TargetSpecific) &&
4956-
!A->isIgnoredTargetSpecific() && !HasAssembleJob) {
4956+
!A->isIgnoredTargetSpecific() && !HasAssembleJob &&
4957+
// When for example -### or -v is used
4958+
// without a file, target specific options are not
4959+
// consumed/validated.
4960+
// Instead emitting an error emit a warning instead.
4961+
!C.getActions().empty()) {
49574962
Diag(diag::err_drv_unsupported_opt_for_target)
49584963
<< A->getSpelling() << getTargetTriple();
49594964
} else {

clang/test/Driver/no-action.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang --target=aarch64-none-gnu --verbose -mcpu= -march= 2>&1 | FileCheck %s --check-prefix=WARNING
2+
// RUN: %clang --target=aarch64-none-gnu -### -mcpu= -march= 2>&1 | FileCheck %s --check-prefix=WARNING
3+
4+
// RUN: %clang --target=x86_64-unknown-linux-gnu --verbose -mcpu= -march= 2>&1 | FileCheck %s --check-prefix=WARNING
5+
// RUN: %clang --target=x86_64-unknown-linux-gnu -### -mcpu= -march= 2>&1 | FileCheck %s --check-prefix=WARNING
6+
7+
/// In situation when there is no compilation/linking clang should not emit error
8+
/// about target specific options, but just warn that are not used.
9+
WARNING: warning: argument unused during compilation
10+
WARNING: warning: argument unused during compilation

0 commit comments

Comments
 (0)