]> granicus.if.org Git - clang/commitdiff
Fix rewrite of reserved library name in case of -nodefaultlibs
authorNirav Dave <niravd@google.com>
Tue, 24 Nov 2015 16:07:21 +0000 (16:07 +0000)
committerNirav Dave <niravd@google.com>
Tue, 24 Nov 2015 16:07:21 +0000 (16:07 +0000)
The Driver only checked if nostdlib was set when deciding to add
reserved_lib_stdcxx, but as nostdlib is always exactly nodefaultlibs and
nostartfiles we should be checking one (clearly nodefaultlibs in the
case) as well. This appears to be the only such instance of this in the
codebase.

Differential Revision: http://reviews.llvm.org/D14935

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253990 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Driver.cpp
test/Driver/nodefaultlib.c

index 5ff57093537cdeb7ad95066b1e3ecefedfe303cd..4f8481c0beeca6e380df252a3aac80f630d524dc 100644 (file)
@@ -209,6 +209,7 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
   DerivedArgList *DAL = new DerivedArgList(Args);
 
   bool HasNostdlib = Args.hasArg(options::OPT_nostdlib);
+  bool HasNodefaultlib = Args.hasArg(options::OPT_nodefaultlibs);
   for (Arg *A : Args) {
     // Unfortunately, we have to parse some forwarding options (-Xassembler,
     // -Xlinker, -Xpreprocessor) because we either integrate their functionality
@@ -252,7 +253,7 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
       StringRef Value = A->getValue();
 
       // Rewrite unless -nostdlib is present.
-      if (!HasNostdlib && Value == "stdc++") {
+      if (!HasNostdlib && !HasNodefaultlib && Value == "stdc++") {
         DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_reserved_lib_stdcxx));
         continue;
       }
index f9462fd27a3d24803c439dd9cabd8c377894f61a..08bcea56fadf65d231d9cd5a0b69b1fc6b6993c4 100644 (file)
@@ -1,8 +1,10 @@
-// RUN: %clang -target i686-pc-linux-gnu -### -nodefaultlibs %s 2> %t
-// RUN: FileCheck < %t %s
-//
-// CHECK-NOT: start-group
-// CHECK-NOT: "-lgcc"
-// CHECK-NOT: "-lc"
-// CHECK: crtbegin
-// CHECK: crtend
+// RUN: %clang -target i686-pc-linux-gnu -### -nodefaultlibs %s 2>&1 | FileCheck -check-prefix=TEST1 %s
+// TEST1-NOT: start-group
+// TEST1-NOT: "-lgcc"
+// TEST1-NOT: "-lc"
+// TEST1: crtbegin
+// TEST1: crtend
+
+// RUN: %clang -target i686-pc-linux-gnu -stdlib=libc++ -nodefaultlibs -lstdc++ -### %s 2>&1 | FileCheck -check-prefix=TEST2 %s
+// TEST2-NOT: "-lc++"
+// TEST2: "-lstdc++"