[clang] b7bac5a - [clang] Revert gcc-driver part of 648feabc65d8

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 13 16:04:56 PDT 2021


Author: Nico Weber
Date: 2021-09-13T19:04:29-04:00
New Revision: b7bac5a172e51ed065b3b4dc64cc2d8831e8081c

URL: https://github.com/llvm/llvm-project/commit/b7bac5a172e51ed065b3b4dc64cc2d8831e8081c
DIFF: https://github.com/llvm/llvm-project/commit/b7bac5a172e51ed065b3b4dc64cc2d8831e8081c.diff

LOG: [clang] Revert gcc-driver part of 648feabc65d8

See discussion on https://reviews.llvm.org/D109624

Added: 
    

Modified: 
    clang/lib/Driver/Driver.cpp
    clang/test/Driver/unknown-arg.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 50791ec479397..0c6b043b5255d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2149,11 +2149,10 @@ bool Driver::DiagnoseInputExistence(const DerivedArgList &Args, StringRef Value,
     }
   }
 
-  // Don't error on apparently non-existent linker inputs, because they
-  // can be influenced by linker flags the clang driver might not understand.
+  // In CL mode, don't error on apparently non-existent linker inputs, because
+  // they can be influenced by linker flags the clang driver might not
+  // understand.
   // Examples:
-  // - `clang -fuse-ld=lld -Wl,--chroot,some/dir /file.o` will make lld look
-  //   for some/dir/file.o
   // - `clang-cl main.cc ole32.lib` in a a non-MSVC shell will make the driver
   //   module look for an MSVC installation in the registry. (We could ask
   //   the MSVCToolChain object if it can find `ole32.lib`, but the logic to
@@ -2172,9 +2171,19 @@ bool Driver::DiagnoseInputExistence(const DerivedArgList &Args, StringRef Value,
   // flag. (Users can use `-Wl,` or `/linker` to launder the flag past the
   // driver in the unlikely case they run into this.)
   //
-  // Don't do this skip in clang-cl mode for inputs that start with a '/' --
-  // else we'd pass options like /libpath: through to the linker silently.
-  if (Ty == types::TY_Object && !(IsCLMode() && Value.startswith("/")))
+  // Don't do this for inputs that start with a '/', else we'd pass options
+  // like /libpath: through to the linker silently.
+  //
+  // Emitting an error for linker inputs can also cause incorrect diagnostics
+  // with the gcc driver. The command
+  //     clang -fuse-ld=lld -Wl,--chroot,some/dir /file.o
+  // will make lld look for some/dir/file.o, while we will diagnose here that
+  // `/file.o` does not exist. However, configure scripts check if
+  // `clang /GR-` compiles without error to see if the compiler is cl.exe,
+  // so we can't downgrade diagnostics for `/GR-` from an error to a warning
+  // in cc mode. (We can in cl mode because cl.exe itself only warns on
+  // unknown flags.)
+  if (IsCLMode() && Ty == types::TY_Object && !Value.startswith("/"))
     return true;
 
   Diag(clang::diag::err_drv_no_such_file) << Value;

diff  --git a/clang/test/Driver/unknown-arg.c b/clang/test/Driver/unknown-arg.c
index 75ae18fa76dde..45752e9c7976d 100644
--- a/clang/test/Driver/unknown-arg.c
+++ b/clang/test/Driver/unknown-arg.c
@@ -23,6 +23,9 @@
 // RUN: not %clang -cc1asphalt -help 2>&1 | \
 // RUN:     FileCheck %s --check-prefix=UNKNOWN-INTEGRATED
 
+// This needs to exit non-0, for configure scripts.
+// RUN: not %clang /GR-
+
 // CHECK: error: unknown argument: '-cake-is-lie'
 // CHECK: error: unknown argument: '-%0'
 // CHECK: error: unknown argument: '-%d'


        


More information about the cfe-commits mailing list