[clang] Check for unsupported target options even with -Qunused-arguments (PR #141698)
Matthias Braun via cfe-commits
cfe-commits at lists.llvm.org
Wed May 28 10:39:34 PDT 2025
https://github.com/MatzeB updated https://github.com/llvm/llvm-project/pull/141698
>From cef4f070167474ac0e8d1eea903974a31ff9934d Mon Sep 17 00:00:00 2001
From: Matthias Braun <matze at braunis.de>
Date: Tue, 27 May 2025 18:20:28 -0700
Subject: [PATCH 1/2] Check for unsupported target options even with
-Qunused-arguments
---
clang/lib/Driver/Driver.cpp | 11 ++++-------
clang/test/Driver/unsupported-option.c | 7 +++++++
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a5a0393ad7912..8d16d3aeeefb6 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5362,12 +5362,6 @@ void Driver::BuildJobs(Compilation &C) const {
});
}
- // If the user passed -Qunused-arguments or there were errors, don't warn
- // about any unused arguments.
- if (Diags.hasErrorOccurred() ||
- C.getArgs().hasArg(options::OPT_Qunused_arguments))
- return;
-
// Claim -fdriver-only here.
(void)C.getArgs().hasArg(options::OPT_fdriver_only);
// Claim -### here.
@@ -5420,7 +5414,10 @@ void Driver::BuildJobs(Compilation &C) const {
!C.getActions().empty()) {
Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getSpelling() << getTargetTriple();
- } else {
+ } else if (!Diags.hasErrorOccurred() &&
+ !C.getArgs().hasArg(options::OPT_Qunused_arguments)) {
+ // If the user passed -Qunused-arguments or there were errors, don't
+ // warn about any unused arguments.
Diag(clang::diag::warn_drv_unused_argument)
<< A->getAsString(C.getArgs());
}
diff --git a/clang/test/Driver/unsupported-option.c b/clang/test/Driver/unsupported-option.c
index af836cf003374..f996772702abc 100644
--- a/clang/test/Driver/unsupported-option.c
+++ b/clang/test/Driver/unsupported-option.c
@@ -27,3 +27,10 @@
// RUN: not %clang --target=x86_64 -### -mhtm -lc %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=UNSUP_OPT
// UNSUP_OPT: error: unsupported option
+
+
+// RUN: not %clang -c --target=aarch64-- -mfpu=crypto-neon-fp-armv8 %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=AARCH64
+// RUN: not %clang -c -Qunused-arguments --target=aarch64-- -mfpu=crypto-neon-fp-armv8 %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=AARCH64
+// AARCH64: error: unsupported option '-mfpu=' for target 'aarch64--'
>From 2fb154e8b305e7e3eb321cf352dd20c028b4e473 Mon Sep 17 00:00:00 2001
From: Matthias Braun <matze at braunis.de>
Date: Wed, 28 May 2025 10:00:06 -0700
Subject: [PATCH 2/2] address review feedback, change logic to check for
HadError earlier
- Address review feedback
- Change logic to check for `HasError()` before the loop again to be
closer to the original behavior; fixes `x86-target-features.c`.
---
clang/lib/Driver/Driver.cpp | 11 +++++++----
clang/test/Driver/unsupported-option.c | 8 +++-----
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8d16d3aeeefb6..6aa0f4c9b1584 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5362,6 +5362,12 @@ void Driver::BuildJobs(Compilation &C) const {
});
}
+ // If the user passed -Qunused-arguments or there were errors, don't
+ // warn about any unused arguments.
+ bool ReportUnusedArguments =
+ !Diags.hasErrorOccurred() &&
+ !C.getArgs().hasArg(options::OPT_Qunused_arguments);
+
// Claim -fdriver-only here.
(void)C.getArgs().hasArg(options::OPT_fdriver_only);
// Claim -### here.
@@ -5414,10 +5420,7 @@ void Driver::BuildJobs(Compilation &C) const {
!C.getActions().empty()) {
Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getSpelling() << getTargetTriple();
- } else if (!Diags.hasErrorOccurred() &&
- !C.getArgs().hasArg(options::OPT_Qunused_arguments)) {
- // If the user passed -Qunused-arguments or there were errors, don't
- // warn about any unused arguments.
+ } else if (ReportUnusedArguments) {
Diag(clang::diag::warn_drv_unused_argument)
<< A->getAsString(C.getArgs());
}
diff --git a/clang/test/Driver/unsupported-option.c b/clang/test/Driver/unsupported-option.c
index f996772702abc..7234e52571582 100644
--- a/clang/test/Driver/unsupported-option.c
+++ b/clang/test/Driver/unsupported-option.c
@@ -29,8 +29,6 @@
// UNSUP_OPT: error: unsupported option
-// RUN: not %clang -c --target=aarch64-- -mfpu=crypto-neon-fp-armv8 %s 2>&1 | \
-// RUN: FileCheck %s --check-prefix=AARCH64
-// RUN: not %clang -c -Qunused-arguments --target=aarch64-- -mfpu=crypto-neon-fp-armv8 %s 2>&1 | \
-// RUN: FileCheck %s --check-prefix=AARCH64
-// AARCH64: error: unsupported option '-mfpu=' for target 'aarch64--'
+// RUN: not %clang -c -Qunused-arguments --target=aarch64-- -mfpu=crypto-neon-fp-armv8 %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=QUNUSED_ARGUMENTS
+// QUNUSED_ARGUMENTS: error: unsupported option '-mfpu=' for target 'aarch64--'
More information about the cfe-commits
mailing list