This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD361518: lld-link, clang: Treat non-existent input files as 
possible spellos for option… (authored by nico, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D62276?vs=200845&id=201017#toc

Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62276/new/

https://reviews.llvm.org/D62276

Files:
  COFF/Driver.cpp
  COFF/DriverUtils.cpp
  test/COFF/color-diagnostics.test
  test/COFF/could-not-open.test
  test/COFF/driver.test
  test/COFF/error-limit.test
  test/COFF/nodefaultlib.test
  test/COFF/responsefile.test

Index: test/COFF/error-limit.test
===================================================================
--- test/COFF/error-limit.test
+++ test/COFF/error-limit.test
@@ -1,26 +1,26 @@
 RUN: not lld-link 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 \
 RUN:   21 22 2>&1 | FileCheck -check-prefix=DEFAULT %s
 
-DEFAULT:      could not open 01
-DEFAULT:      could not open 20
+DEFAULT:      could not open '01'
+DEFAULT:      could not open '20'
 DEFAULT-NEXT: too many errors emitted, stopping now (use /errorlimit:0 to see all errors)
-DEFAULT-NOT:  could not open 21
+DEFAULT-NOT:  could not open '21'
 
 RUN: not lld-link /errorlimit:5 01 02 03 04 05 06 07 08 09 10 2>&1 \
 RUN:   | FileCheck -check-prefix=LIMIT5 %s
 
-LIMIT5:      could not open 01
-LIMIT5:      could not open 05
+LIMIT5:      could not open '01'
+LIMIT5:      could not open '05'
 LIMIT5-NEXT: too many errors emitted, stopping now (use /errorlimit:0 to see all errors)
-LIMIT5-NOT:  could not open 06
+LIMIT5-NOT:  could not open '06'
 
 RUN: not lld-link /errorlimit:0 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 \
 RUN:   16 17 18 19 20 21 22 2>&1 | FileCheck -check-prefix=UNLIMITED %s
 
-UNLIMITED:     could not open 01
-UNLIMITED:     could not open 20
-UNLIMITED:     could not open 21
-UNLIMITED:     could not open 22
+UNLIMITED:     could not open '01'
+UNLIMITED:     could not open '20'
+UNLIMITED:     could not open '21'
+UNLIMITED:     could not open '22'
 UNLIMITED-NOT: too many errors emitted, stopping now (use /errorlimit:0 to see all errors)
 
 RUN: not lld-link /errorlimit:XYZ 01 02 03 04 05 06 07 08 09 10 11 12 13 14 \
Index: test/COFF/nodefaultlib.test
===================================================================
--- test/COFF/nodefaultlib.test
+++ test/COFF/nodefaultlib.test
@@ -19,8 +19,8 @@
 # RUN:   /nodefaultlib:std64.lib >& %t.log || true
 # RUN: FileCheck -check-prefix=CHECK3 %s < %t.log
 
-CHECK1: error: could not open hello64.obj: {{[Nn]}}o such file or directory
-CHECK2: error: could not open hello64: {{[Nn]}}o such file or directory
+CHECK1: error: could not open 'hello64.obj': {{[Nn]}}o such file or directory
+CHECK2: error: could not open 'hello64': {{[Nn]}}o such file or directory
 CHECK3: error: undefined symbol: MessageBoxA
 CHECK3-NEXT: >>> referenced by {{.*}}hello64.obj:(main)
 
Index: test/COFF/responsefile.test
===================================================================
--- test/COFF/responsefile.test
+++ test/COFF/responsefile.test
@@ -12,14 +12,14 @@
 # RUN: echo "blah\foo" > %t.rsp
 # RUN: not lld-link @%t.rsp 2>&1 | \
 # RUN:     FileCheck --check-prefix=DEFRSP %s
-DEFRSP: error: could not open blah\foo
+DEFRSP: error: could not open 'blah\foo'
 
 # RUN: echo "blah\foo" > %t.rsp
 # RUN: not lld-link --rsp-quoting=windows @%t.rsp 2>&1 | \
 # RUN:     FileCheck --check-prefix=WINRSP %s
-WINRSP: error: could not open blah\foo
+WINRSP: error: could not open 'blah\foo'
 
 # RUN: echo "blah\foo" > %t.rsp
 # RUN: not lld-link --rsp-quoting=posix @%t.rsp 2>&1 | \
 # RUN:     FileCheck --check-prefix=POSRSP %s
-POSRSP: error: could not open blahfoo
+POSRSP: error: could not open 'blahfoo'
Index: test/COFF/color-diagnostics.test
===================================================================
--- test/COFF/color-diagnostics.test
+++ test/COFF/color-diagnostics.test
@@ -7,7 +7,7 @@
 # RUN:   | FileCheck -check-prefix=COLOR %s
 
 # COLOR: {{lld-link: .\[0;1;35mwarning: .\[0mignoring unknown argument '-xyz'}}
-# COLOR: {{lld-link: .\[0;1;31merror: .\[0mcould not open /nosuchfile}}
+# COLOR: {{lld-link: .\[0;1;31merror: .\[0mcould not open '/nosuchfile'}}
 
 # RUN: not lld-link /nosuchfile 2>&1 | FileCheck -check-prefix=NOCOLOR %s
 # RUN: not lld-link -color-diagnostics=never /nosuchfile 2>&1 \
@@ -15,4 +15,4 @@
 # RUN: not lld-link -color-diagnostics=always -no-color-diagnostics \
 # RUN:   /nosuchfile 2>&1 | FileCheck -check-prefix=NOCOLOR %s
 
-# NOCOLOR: lld-link: error: could not open /nosuchfile
+# NOCOLOR: lld-link: error: could not open '/nosuchfile'
Index: test/COFF/could-not-open.test
===================================================================
--- test/COFF/could-not-open.test
+++ test/COFF/could-not-open.test
@@ -1,5 +1,5 @@
 RUN: not lld-link 01 2>&1 | FileCheck %s
 
-CHECK:     could not open 01
+CHECK:     could not open '01'
 CHECK-NOT: /machine is not specified
 CHECK-NOT: subsystem must be defined
Index: test/COFF/driver.test
===================================================================
--- test/COFF/driver.test
+++ test/COFF/driver.test
@@ -1,6 +1,6 @@
 # RUN: not lld-link nosuchfile.obj >& %t.log
 # RUN: FileCheck -check-prefix=MISSING %s < %t.log
-MISSING: nosuchfile.obj: {{[Nn]}}o such file or directory
+MISSING: 'nosuchfile.obj': {{[Nn]}}o such file or directory
 
 # RUN: lld-link --version | FileCheck -check-prefix=VERSION %s
 VERSION: {{LLD [0-9]+\.[0-9]+}}
@@ -27,3 +27,13 @@
 # RUN: not lld-link -nodefaultlibs 2>&1 | FileCheck -check-prefix=SPELLNODEFAULTLIB %s
 SPELLNODEFAULTLIB: ignoring unknown argument '-nodefaultlibs', did you mean '-nodefaultlib'
 SPELLNODEFAULTLIB: no input files
+
+# RUN: not lld-link /nodefaultlibs 2>&1 | FileCheck -check-prefix=SPELLNODEFAULTLIB_SLASH %s
+SPELLNODEFAULTLIB_SLASH: could not open '/nodefaultlibs': {{.*}}; did you mean '/nodefaultlib'
+SPELLNODEFAULTLIB_SLASH-NOT: no input files
+
+# Getting flags as typo corrections for normal input files is a side effect
+# of how spell checking for /-style flags is implemented.
+# RUN: not lld-link force 2>&1 | FileCheck -check-prefix=SPELLFORCE %s
+SPELLFORCE: could not open 'force': {{.*}}; did you mean '/force'
+SPELLFORCE-NOT: no input files
Index: COFF/DriverUtils.cpp
===================================================================
--- COFF/DriverUtils.cpp
+++ COFF/DriverUtils.cpp
@@ -833,7 +833,8 @@
 
   // Expand response files (arguments in the form of @<filename>)
   // and then parse the argument again.
-  SmallVector<const char *, 256> ExpandedArgv(Argv.data(), Argv.data() + Argv.size());
+  SmallVector<const char *, 256> ExpandedArgv(Argv.data(),
+                                              Argv.data() + Argv.size());
   cl::ExpandResponseFiles(Saver, getQuotingStyle(Args), ExpandedArgv);
   Args = Table.ParseArgs(makeArrayRef(ExpandedArgv).drop_front(), MissingIndex,
                          MissingCount);
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -203,9 +203,20 @@
   std::string PathStr = Path;
   enqueueTask([=]() {
     auto MBOrErr = Future->get();
-    if (MBOrErr.second)
-      error("could not open " + PathStr + ": " + MBOrErr.second.message());
-    else
+    if (MBOrErr.second) {
+      std::string Error =
+          "could not open '" + PathStr + "': " + MBOrErr.second.message();
+      // Check if the filename is a typo for an option flag. OptTable thinks
+      // that all args that are not known options and that start with / are
+      // filenames, but e.g. `/nodefaultlibs` is more likely a typo for
+      // the option `/nodefaultlib` than a reference to a file in the root
+      // directory.
+      std::string Nearest;
+      if (COFFOptTable().findNearest(PathStr, Nearest) > 1)
+        error(Error);
+      else
+        error(Error + "; did you mean '" + Nearest + "'");
+    } else
       Driver->addBuffer(std::move(MBOrErr.first), WholeArchive);
   });
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to