Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2653,22 +2653,13 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
Diag(clang::diag::note_drv_t_option_is_global);
}

// CUDA/HIP and their preprocessor expansions can be accepted by CL mode.
// Warn -x after last input file has no effect
auto LastXArg = Args.getLastArgValue(options::OPT_x);
const llvm::StringSet<> ValidXArgs = {"cuda", "hip", "cui", "hipi"};
if (!IsCLMode() || ValidXArgs.contains(LastXArg)) {
{
Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x);
Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT);
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) {
Expand Down
4 changes: 1 addition & 3 deletions clang/test/Driver/x-args.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
// 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 /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'?
// RUN: %clang_cl -fsyntax-only /WX -xc++ -- %s