[PATCH] D109624: [clang] Make the driver not diagnose errors on nonexistent linker inputs

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 12:23:10 PDT 2021


thakis added inline comments.


================
Comment at: clang/lib/Driver/Driver.cpp:2173
+  // flag. (Users can use `-Wl,` or `/linker` to launder the flag past the
+  // driver in the unlikely case they run into this.)
+  if (Ty == types::TY_Object)
----------------
thakis wrote:
> This means that typo suggestion now works even if you pass `/link`. Before this patch, it didn't:
> 
> ```
> % out/gn/bin/clang-cl /Brepo -### clang/test/Driver/unknown-arg.c /link
> clang: error: no such file or directory: '/Brepo'; did you mean '/Brepro'?
> ```
> 
> I suppose this means that before, we unintentionally and silently passed flags that clang-cl didn't know to link.exe even if they were in front of `/link`!  …and we _still_ do this for flags that aren't within editing distance of 1 of existing clang-cl flags:
> 
> ```
> % out/gn/bin/clang-cl clang/test/Driver/unknown-arg.c /asdfasdf -fuse-ld=lld /link
> lld-link: error: could not open '/asdfasdf': No such file or directory
> ```
> 
> Now we even do this if there's no `/link` flag:
> 
> ```
> % out/gn/bin/clang-cl clang/test/Driver/unknown-arg.c /libpath:foo -fuse-ld=lld
> # fine
> ```
> 
> That's kind of weird! With `-` we do something better:
> 
> ```
> % out/gn/bin/clang-cl clang/test/Driver/unknown-arg.c -libpath:foo -fuse-ld=lld
> clang: warning: unknown argument ignored in clang-cl: '-libpath:foo' [-Wunknown-argument]
> ```
> 
> It's the old "things starting with '/' might be path, or might be flag" thing again, and as the --chroot example in this comment shows, it actually might be a path even if no file exists at that particular path. Hrm.
Maybe we should tack on a `&& !(IsCLMode() && Value.startswith("/"))` here for that? (lld-)link.exe don't have a feature like `-chroot` as far as I know. It's a bit heuristic-y, but probably better than not doing it?


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

https://reviews.llvm.org/D109624



More information about the llvm-commits mailing list