[clang] fe08212 - [clang][driver] Emit an error for `/clang:-x`
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 2 08:54:09 PST 2023
Author: Mariya Podchishchaeva
Date: 2023-02-02T11:48:33-05:00
New Revision: fe082124faa8455cc9a68be5fdf10fc46a4d066c
URL: https://github.com/llvm/llvm-project/commit/fe082124faa8455cc9a68be5fdf10fc46a4d066c
DIFF: https://github.com/llvm/llvm-project/commit/fe082124faa8455cc9a68be5fdf10fc46a4d066c.diff
LOG: [clang][driver] Emit an error for `/clang:-x`
`/clang:-x` emits an error instead of a warning. And if the error is suppressed,
`/clang:-x` takes no effect.
Considering that `/clang:` is a recent addition in 2018-11 and there are MSVC
style alternatives, therefore `/clang:-x` doesn't seem useful and we just reject
it since properly supporting it would add lots of complexity.
Fixes #59307
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D142757
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Driver/Driver.cpp
clang/test/Driver/x-args.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9cc2a72f4c86..4a86b379dda9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -60,6 +60,10 @@ Bug Fixes
- Fix crash when diagnosing incorrect usage of ``_Nullable`` involving alias
templates. This fixes
`Issue 60344 <https://github.com/llvm/llvm-project/issues/60344>`_.
+- Fix confusing warning message when ``/clang:-x`` is passed in ``clang-cl``
+ driver mode and emit an error which suggests using ``/TC`` or ``/TP``
+ ``clang-cl`` options instead. This fixes
+ `Issue 59307 <https://github.com/llvm/llvm-project/issues/59307>`_.
Improvements to Clang's diagnostics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 98c0edc02ba6..6c0ff3d30e64 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2566,17 +2566,21 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
}
if (ShowNote)
Diag(clang::diag::note_drv_t_option_is_global);
-
- // No driver mode exposes -x and /TC or /TP; we don't support mixing them.
- assert(!Args.hasArg(options::OPT_x) && "-x and /TC or /TP is not allowed");
}
// Warn -x after last input file has no effect
- {
+ if (!IsCLMode()) {
Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x);
Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT);
- if (LastXArg && LastInputArg && LastInputArg->getIndex() < LastXArg->getIndex())
+ if (LastXArg && LastInputArg &&
+ LastInputArg->getIndex() < LastXArg->getIndex())
Diag(clang::diag::warn_drv_unused_x) << LastXArg->getValue();
+ } else {
+ // In CL mode suggest /TC or /TP since -x doesn't make sense if passed via
+ // /clang:.
+ if (auto *A = Args.getLastArg(options::OPT_x))
+ Diag(diag::err_drv_unsupported_opt_with_suggestion)
+ << A->getAsString(Args) << "/TC' or '/TP";
}
for (Arg *A : Args) {
diff --git a/clang/test/Driver/x-args.c b/clang/test/Driver/x-args.c
index b49f474babf0..daaa47bad892 100644
--- a/clang/test/Driver/x-args.c
+++ b/clang/test/Driver/x-args.c
@@ -5,3 +5,8 @@
// RUN: %clang -fsyntax-only -xc %s -xc++ -fsyntax-only 2>&1 | FileCheck %s
// RUN: %clang -fsyntax-only %s -xc %s -xc++ -fsyntax-only 2>&1 | FileCheck %s
// CHECK: '-x c++' after last input file has no effect
+
+// RUN: not %clang_cl /WX /clang:-xc /clang:-E /clang:-dM %s 2>&1 | FileCheck --implicit-check-not="error:" -check-prefix=CL %s
+// RUN: not %clang_cl /WX /clang:-E /clang:-dM %s /clang:-xc 2>&1 | FileCheck --implicit-check-not="error:" -check-prefix=CL %s
+// RUN: not %clang_cl /TC /WX /clang:-xc /clang:-E /clang:-dM %s 2>&1 | FileCheck --implicit-check-not="error:" -check-prefix=CL %s
+// CL: error: unsupported option '-x c'; did you mean '/TC' or '/TP'?
More information about the cfe-commits
mailing list