Skip to content

Commit 06b5a7c

Browse files
authored
[clang][driver] Support -x for all languages in CL mode (#89772)
After #68921, clang-cl gained option `-x` but only for CUDA/HIP. This commit simply removes the restriction on parameters to `-x`. Especially, it is able to use `-x c++-module` and `-x c++-system-header` to build C++20 modules and header units with clang-cl. This effectively reverts commit fe08212. Closes #88006.
1 parent 3c9641e commit 06b5a7c

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,22 +2653,13 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
26532653
Diag(clang::diag::note_drv_t_option_is_global);
26542654
}
26552655

2656-
// CUDA/HIP and their preprocessor expansions can be accepted by CL mode.
26572656
// Warn -x after last input file has no effect
2658-
auto LastXArg = Args.getLastArgValue(options::OPT_x);
2659-
const llvm::StringSet<> ValidXArgs = {"cuda", "hip", "cui", "hipi"};
2660-
if (!IsCLMode() || ValidXArgs.contains(LastXArg)) {
2657+
{
26612658
Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x);
26622659
Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT);
26632660
if (LastXArg && LastInputArg &&
26642661
LastInputArg->getIndex() < LastXArg->getIndex())
26652662
Diag(clang::diag::warn_drv_unused_x) << LastXArg->getValue();
2666-
} else {
2667-
// In CL mode suggest /TC or /TP since -x doesn't make sense if passed via
2668-
// /clang:.
2669-
if (auto *A = Args.getLastArg(options::OPT_x))
2670-
Diag(diag::err_drv_unsupported_opt_with_suggestion)
2671-
<< A->getAsString(Args) << "/TC' or '/TP";
26722663
}
26732664

26742665
for (Arg *A : Args) {

clang/test/Driver/x-args.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
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
88

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 /TC /WX /clang:-xc /clang:-E /clang:-dM -- %s 2>&1 | FileCheck --implicit-check-not="error:" -check-prefix=CL %s
11-
// CL: error: unsupported option '-x c'; did you mean '/TC' or '/TP'?
9+
// RUN: %clang_cl -fsyntax-only /WX -xc++ -- %s

0 commit comments

Comments
 (0)