diff options
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticDriverKinds.td | 4 | ||||
| -rw-r--r-- | clang/lib/Driver/Driver.cpp | 8 | ||||
| -rw-r--r-- | clang/test/Driver/cl-options.c | 6 |
3 files changed, 18 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 2fcd3a5a2fb..596ef273a26 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -247,6 +247,10 @@ def err_test_module_file_extension_format : Error< def warn_drv_invoking_fallback : Warning<"falling back to %0">, InGroup<Fallback>; +def warn_slash_u_filename : Warning<"'/U%0' treated as the '/U' option">, + InGroup<DiagGroup<"slash-u-filename">>; +def note_use_dashdash : Note<"Use '--' to treat subsequent arguments as filenames">; + def err_drv_ropi_rwpi_incompatible_with_pic : Error< "embedded and GOT-based position independence are incompatible">; def err_drv_ropi_incompatible_with_cxx : Error< diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index f16acbb42e9..0dcab7c0c6c 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1583,6 +1583,14 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args, Diag(clang::diag::err_drv_unknown_language) << A->getValue(); InputType = types::TY_Object; } + } else if (A->getOption().getID() == options::OPT__SLASH_U) { + assert(A->getNumValues() == 1 && "The /U option has one value."); + StringRef Val = A->getValue(0); + if (Val.find_first_of("/\\") != StringRef::npos) { + // Warn about e.g. "/Users/me/myfile.c". + Diag(diag::warn_slash_u_filename) << Val; + Diag(diag::note_use_dashdash); + } } } if (CCCIsCPP() && Inputs.empty()) { diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c index 69238227c54..232cdce1078 100644 --- a/clang/test/Driver/cl-options.c +++ b/clang/test/Driver/cl-options.c @@ -442,6 +442,12 @@ // Xclang: "-cc1" // Xclang: "hellocc1" +// Files under /Users are often confused with the /U flag. (This could happen +// for other flags too, but this is the one people run into.) +// RUN: %clang_cl /c /Users/me/myfile.c -### 2>&1 | FileCheck -check-prefix=SlashU %s +// SlashU: warning: '/Users/me/myfile.c' treated as the '/U' option +// SlashU: note: Use '--' to treat subsequent arguments as filenames + // RTTI is on by default. /GR- controls -fno-rtti-data. // RUN: %clang_cl /c /GR- -### -- %s 2>&1 | FileCheck -check-prefix=NoRTTI %s // NoRTTI: "-fno-rtti-data" |

