r349570 - [Driver] Also obey -nostdlib++ when rewriting -lstdc++.

Dan Albert via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 18 15:29:35 PST 2018


Author: danalbert
Date: Tue Dec 18 15:29:35 2018
New Revision: 349570

URL: http://llvm.org/viewvc/llvm-project?rev=349570&view=rev
Log:
[Driver] Also obey -nostdlib++ when rewriting -lstdc++.

Reviewers: pirama

Reviewed By: pirama

Subscribers: cfe-commits

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

Modified:
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/test/Driver/nostdlibxx.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=349570&r1=349569&r2=349570&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Dec 18 15:29:35 2018
@@ -303,6 +303,7 @@ DerivedArgList *Driver::TranslateInputAr
   DerivedArgList *DAL = new DerivedArgList(Args);
 
   bool HasNostdlib = Args.hasArg(options::OPT_nostdlib);
+  bool HasNostdlibxx = Args.hasArg(options::OPT_nostdlibxx);
   bool HasNodefaultlib = Args.hasArg(options::OPT_nodefaultlibs);
   for (Arg *A : Args) {
     // Unfortunately, we have to parse some forwarding options (-Xassembler,
@@ -347,7 +348,8 @@ DerivedArgList *Driver::TranslateInputAr
       StringRef Value = A->getValue();
 
       // Rewrite unless -nostdlib is present.
-      if (!HasNostdlib && !HasNodefaultlib && Value == "stdc++") {
+      if (!HasNostdlib && !HasNodefaultlib && !HasNostdlibxx &&
+          Value == "stdc++") {
         DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_reserved_lib_stdcxx));
         continue;
       }

Modified: cfe/trunk/test/Driver/nostdlibxx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/nostdlibxx.cpp?rev=349570&r1=349569&r2=349570&view=diff
==============================================================================
--- cfe/trunk/test/Driver/nostdlibxx.cpp (original)
+++ cfe/trunk/test/Driver/nostdlibxx.cpp Tue Dec 18 15:29:35 2018
@@ -6,3 +6,12 @@
 // CHECK-NOT: -lstdc++
 // CHECK-NOT: -lc++
 // CHECK: -lm
+
+// Make sure -lstdc++ isn't rewritten to the default stdlib when -nostdlib++ is
+// used.
+//
+// RUN: %clangxx -target i686-pc-linux-gnu -### \
+// RUN:     -nostdlib++ -stdlib=libc++ -lstdc++ %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-RESERVED-LIB-REWRITE < %t %s
+// CHECK-RESERVED-LIB-REWRITE: -lstdc++
+// CHECK-RESERVED-LIB-REWRITE-NOT: -lc++




More information about the cfe-commits mailing list