Skip to content

Commit fe08212

Browse files
committed
[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 llvm#59307 Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D142757
1 parent 9b06f75 commit fe08212

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ Bug Fixes
6060
- Fix crash when diagnosing incorrect usage of ``_Nullable`` involving alias
6161
templates. This fixes
6262
`Issue 60344 <https://github.com/llvm/llvm-project/issues/60344>`_.
63+
- Fix confusing warning message when ``/clang:-x`` is passed in ``clang-cl``
64+
driver mode and emit an error which suggests using ``/TC`` or ``/TP``
65+
``clang-cl`` options instead. This fixes
66+
`Issue 59307 <https://github.com/llvm/llvm-project/issues/59307>`_.
6367

6468
Improvements to Clang's diagnostics
6569
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Driver/Driver.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,17 +2566,21 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
25662566
}
25672567
if (ShowNote)
25682568
Diag(clang::diag::note_drv_t_option_is_global);
2569-
2570-
// No driver mode exposes -x and /TC or /TP; we don't support mixing them.
2571-
assert(!Args.hasArg(options::OPT_x) && "-x and /TC or /TP is not allowed");
25722569
}
25732570

25742571
// Warn -x after last input file has no effect
2575-
{
2572+
if (!IsCLMode()) {
25762573
Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x);
25772574
Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT);
2578-
if (LastXArg && LastInputArg && LastInputArg->getIndex() < LastXArg->getIndex())
2575+
if (LastXArg && LastInputArg &&
2576+
LastInputArg->getIndex() < LastXArg->getIndex())
25792577
Diag(clang::diag::warn_drv_unused_x) << LastXArg->getValue();
2578+
} else {
2579+
// In CL mode suggest /TC or /TP since -x doesn't make sense if passed via
2580+
// /clang:.
2581+
if (auto *A = Args.getLastArg(options::OPT_x))
2582+
Diag(diag::err_drv_unsupported_opt_with_suggestion)
2583+
<< A->getAsString(Args) << "/TC' or '/TP";
25802584
}
25812585

25822586
for (Arg *A : Args) {

clang/test/Driver/x-args.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
// RUN: %clang -fsyntax-only -xc %s -xc++ -fsyntax-only 2>&1 | FileCheck %s
66
// RUN: %clang -fsyntax-only %s -xc %s -xc++ -fsyntax-only 2>&1 | FileCheck %s
77
// CHECK: '-x c++' after last input file has no effect
8+
9+
// RUN: not %clang_cl /WX /clang:-xc /clang:-E /clang:-dM %s 2>&1 | FileCheck --implicit-check-not="error:" -check-prefix=CL %s
10+
// RUN: not %clang_cl /WX /clang:-E /clang:-dM %s /clang:-xc 2>&1 | FileCheck --implicit-check-not="error:" -check-prefix=CL %s
11+
// RUN: not %clang_cl /TC /WX /clang:-xc /clang:-E /clang:-dM %s 2>&1 | FileCheck --implicit-check-not="error:" -check-prefix=CL %s
12+
// CL: error: unsupported option '-x c'; did you mean '/TC' or '/TP'?

0 commit comments

Comments
 (0)