Skip to content

Commit 9d89def

Browse files
committed
[clang][driver] Support -x for all languages in CL mode
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++-user-header` to build C++20 modules and header units with clang-cl. This effectively reverts commit fe08212. Closes #88006.
1 parent 298f8f7 commit 9d89def

File tree

2 files changed

+1
-14
lines changed

2 files changed

+1
-14
lines changed

clang/lib/Driver/Driver.cpp

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

2639-
// CUDA/HIP and their preprocessor expansions can be accepted by CL mode.
26402639
// Warn -x after last input file has no effect
2641-
auto LastXArg = Args.getLastArgValue(options::OPT_x);
2642-
const llvm::StringSet<> ValidXArgs = {"cuda", "hip", "cui", "hipi"};
2643-
if (!IsCLMode() || ValidXArgs.contains(LastXArg)) {
2640+
{
26442641
Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x);
26452642
Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT);
26462643
if (LastXArg && LastInputArg &&
26472644
LastInputArg->getIndex() < LastXArg->getIndex())
26482645
Diag(clang::diag::warn_drv_unused_x) << LastXArg->getValue();
2649-
} else {
2650-
// In CL mode suggest /TC or /TP since -x doesn't make sense if passed via
2651-
// /clang:.
2652-
if (auto *A = Args.getLastArg(options::OPT_x))
2653-
Diag(diag::err_drv_unsupported_opt_with_suggestion)
2654-
<< A->getAsString(Args) << "/TC' or '/TP";
26552646
}
26562647

26572648
for (Arg *A : Args) {

clang/test/Driver/x-args.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,3 @@
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 /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'?

0 commit comments

Comments
 (0)