Re: r361518 - lld-link, clang: Treat non-existent input files as possible spellos for option flags

2019-05-27 Thread Hans Wennborg via cfe-commits
Want to put a note in ReleaseNotes.rst?

This is fixing something that a lot of users have run in to, so seems
worth mentioning :-)

On Thu, May 23, 2019 at 7:55 PM Nico Weber via cfe-commits
 wrote:
>
> Author: nico
> Date: Thu May 23 10:58:33 2019
> New Revision: 361518
>
> URL: http://llvm.org/viewvc/llvm-project?rev=361518=rev
> Log:
> lld-link, clang: Treat non-existent input files as possible spellos for 
> option flags
>
> OptTable treats arguments starting with / that aren't a known option
> as filenames. This means lld-link's and clang-cl's typo correction for
> unknown flags didn't do spell checking for misspelled options that start
> with /.
>
> I first tried changing OptTable, but that got pretty messy, see PR41787
> comments 2 and 3.
>
> Instead, let lld-link's and clang's (including clang-cl's) "file not
> found" diagnostic check if a non-existent file looks like it could be a
> mis-spelled option, and if so add a "did you mean" suggestion to the
> "file not found" diagnostic.
>
> While here, make formatting of a few diagnostics a bit more
> self-consistent.
>
> Fixes PR41787.
>
> Differential Revision: https://reviews.llvm.org/D62276
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> cfe/trunk/include/clang/Driver/Driver.h
> cfe/trunk/lib/Driver/Driver.cpp
> cfe/trunk/test/Driver/unknown-arg.c
> cfe/trunk/test/Driver/unsupported-option.c
> cfe/trunk/test/Frontend/unknown-arg.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=361518=361517=361518=diff
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu May 23 
> 10:58:33 2019
> @@ -9,9 +9,11 @@
>  let Component = "Driver" in {
>
>  def err_drv_no_such_file : Error<"no such file or directory: '%0'">;
> +def err_drv_no_such_file_with_suggestion : Error<
> +  "no such file or directory: '%0'; did you mean '%1'?">;
>  def err_drv_unsupported_opt : Error<"unsupported option '%0'">;
> -def err_drv_unsupported_opt_with_suggestion
> -  : Error<"unsupported option '%0', did you mean '%1'?">;
> +def err_drv_unsupported_opt_with_suggestion : Error<
> +  "unsupported option '%0'; did you mean '%1'?">;
>  def err_drv_unsupported_opt_for_target : Error<
>"unsupported option '%0' for target '%1'">;
>  def err_drv_unsupported_option_argument : Error<
> @@ -166,13 +168,13 @@ def err_arch_unsupported_isa
>  def err_drv_I_dash_not_supported : Error<
>"'%0' not supported, please use -iquote instead">;
>  def err_drv_unknown_argument : Error<"unknown argument: '%0'">;
> -def err_drv_unknown_argument_with_suggestion
> -  : Error<"unknown argument '%0', did you mean '%1'?">;
> +def err_drv_unknown_argument_with_suggestion : Error<
> +  "unknown argument '%0'; did you mean '%1'?">;
>  def warn_drv_unknown_argument_clang_cl : Warning<
>"unknown argument ignored in clang-cl: '%0'">,
>InGroup;
>  def warn_drv_unknown_argument_clang_cl_with_suggestion : Warning<
> -  "unknown argument ignored in clang-cl '%0' (did you mean '%1'?)">,
> +  "unknown argument ignored in clang-cl '%0'; did you mean '%1'?">,
>InGroup;
>
>  def warn_drv_ycyu_different_arg_clang_cl : Warning<
>
> Modified: cfe/trunk/include/clang/Driver/Driver.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=361518=361517=361518=diff
> ==
> --- cfe/trunk/include/clang/Driver/Driver.h (original)
> +++ cfe/trunk/include/clang/Driver/Driver.h Thu May 23 10:58:33 2019
> @@ -394,6 +394,14 @@ public:
>void BuildUniversalActions(Compilation , const ToolChain ,
>   const InputList ) const;
>
> +  /// Check that the file referenced by Value exists. If it doesn't,
> +  /// issue a diagnostic and return false.
> +  /// If TypoCorrect is true and the file does not exist, see if it looks
> +  /// like a likely typo for a flag and if so print a "did you mean" blurb.
> +  bool DiagnoseInputExistence(const llvm::opt::DerivedArgList ,
> +  StringRef Value, types::ID Ty,
> +  bool TypoCorrect) const;
> +
>/// BuildJobs - Bind actions to concrete tools and translate
>/// arguments to form the list of jobs to run.
>///
>
> Modified: cfe/trunk/lib/Driver/Driver.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=361518=361517=361518=diff
> ==
> --- cfe/trunk/lib/Driver/Driver.cpp (original)
> +++ cfe/trunk/lib/Driver/Driver.cpp Thu May 23 10:58:33 2019
> @@ -1975,11 +1975,9 @@ void Driver::BuildUniversalActions(Compi
>}
>  }
>
> -/// Check that the file 

r361518 - lld-link, clang: Treat non-existent input files as possible spellos for option flags

2019-05-23 Thread Nico Weber via cfe-commits
Author: nico
Date: Thu May 23 10:58:33 2019
New Revision: 361518

URL: http://llvm.org/viewvc/llvm-project?rev=361518=rev
Log:
lld-link, clang: Treat non-existent input files as possible spellos for option 
flags

OptTable treats arguments starting with / that aren't a known option
as filenames. This means lld-link's and clang-cl's typo correction for
unknown flags didn't do spell checking for misspelled options that start
with /.

I first tried changing OptTable, but that got pretty messy, see PR41787
comments 2 and 3.

Instead, let lld-link's and clang's (including clang-cl's) "file not
found" diagnostic check if a non-existent file looks like it could be a
mis-spelled option, and if so add a "did you mean" suggestion to the
"file not found" diagnostic.

While here, make formatting of a few diagnostics a bit more
self-consistent.

Fixes PR41787.

Differential Revision: https://reviews.llvm.org/D62276

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Driver/Driver.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/test/Driver/unknown-arg.c
cfe/trunk/test/Driver/unsupported-option.c
cfe/trunk/test/Frontend/unknown-arg.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=361518=361517=361518=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu May 23 10:58:33 
2019
@@ -9,9 +9,11 @@
 let Component = "Driver" in {
 
 def err_drv_no_such_file : Error<"no such file or directory: '%0'">;
+def err_drv_no_such_file_with_suggestion : Error<
+  "no such file or directory: '%0'; did you mean '%1'?">;
 def err_drv_unsupported_opt : Error<"unsupported option '%0'">;
-def err_drv_unsupported_opt_with_suggestion
-  : Error<"unsupported option '%0', did you mean '%1'?">;
+def err_drv_unsupported_opt_with_suggestion : Error<
+  "unsupported option '%0'; did you mean '%1'?">;
 def err_drv_unsupported_opt_for_target : Error<
   "unsupported option '%0' for target '%1'">;
 def err_drv_unsupported_option_argument : Error<
@@ -166,13 +168,13 @@ def err_arch_unsupported_isa
 def err_drv_I_dash_not_supported : Error<
   "'%0' not supported, please use -iquote instead">;
 def err_drv_unknown_argument : Error<"unknown argument: '%0'">;
-def err_drv_unknown_argument_with_suggestion
-  : Error<"unknown argument '%0', did you mean '%1'?">;
+def err_drv_unknown_argument_with_suggestion : Error<
+  "unknown argument '%0'; did you mean '%1'?">;
 def warn_drv_unknown_argument_clang_cl : Warning<
   "unknown argument ignored in clang-cl: '%0'">,
   InGroup;
 def warn_drv_unknown_argument_clang_cl_with_suggestion : Warning<
-  "unknown argument ignored in clang-cl '%0' (did you mean '%1'?)">,
+  "unknown argument ignored in clang-cl '%0'; did you mean '%1'?">,
   InGroup;
 
 def warn_drv_ycyu_different_arg_clang_cl : Warning<

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=361518=361517=361518=diff
==
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Thu May 23 10:58:33 2019
@@ -394,6 +394,14 @@ public:
   void BuildUniversalActions(Compilation , const ToolChain ,
  const InputList ) const;
 
+  /// Check that the file referenced by Value exists. If it doesn't,
+  /// issue a diagnostic and return false.
+  /// If TypoCorrect is true and the file does not exist, see if it looks
+  /// like a likely typo for a flag and if so print a "did you mean" blurb.
+  bool DiagnoseInputExistence(const llvm::opt::DerivedArgList ,
+  StringRef Value, types::ID Ty,
+  bool TypoCorrect) const;
+
   /// BuildJobs - Bind actions to concrete tools and translate
   /// arguments to form the list of jobs to run.
   ///

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=361518=361517=361518=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu May 23 10:58:33 2019
@@ -1975,11 +1975,9 @@ void Driver::BuildUniversalActions(Compi
   }
 }
 
-/// Check that the file referenced by Value exists. If it doesn't,
-/// issue a diagnostic and return false.
-static bool DiagnoseInputExistence(const Driver , const DerivedArgList ,
-   StringRef Value, types::ID Ty) {
-  if (!D.getCheckInputsExist())
+bool Driver::DiagnoseInputExistence(const DerivedArgList , StringRef 
Value,
+types::ID Ty, bool