r253990 - Fix rewrite of reserved library name in case of -nodefaultlibs

Nirav Dave via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 24 08:07:22 PST 2015


Author: niravd
Date: Tue Nov 24 10:07:21 2015
New Revision: 253990

URL: http://llvm.org/viewvc/llvm-project?rev=253990&view=rev
Log:
Fix rewrite of reserved library name in case of -nodefaultlibs

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

Modified:
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/test/Driver/nodefaultlib.c

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=253990&r1=253989&r2=253990&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Nov 24 10:07:21 2015
@@ -209,6 +209,7 @@ DerivedArgList *Driver::TranslateInputAr
   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::TranslateInputAr
       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;
       }

Modified: cfe/trunk/test/Driver/nodefaultlib.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/nodefaultlib.c?rev=253990&r1=253989&r2=253990&view=diff
==============================================================================
--- cfe/trunk/test/Driver/nodefaultlib.c (original)
+++ cfe/trunk/test/Driver/nodefaultlib.c Tue Nov 24 10:07:21 2015
@@ -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++"




More information about the cfe-commits mailing list