From: Nirav Dave Date: Tue, 24 Nov 2015 16:07:21 +0000 (+0000) Subject: Fix rewrite of reserved library name in case of -nodefaultlibs X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=449c5870aca4e5f2a35b20ac859fca3b8d3699de;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253990 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 5ff5709353..4f8481c0be 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -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; } diff --git a/test/Driver/nodefaultlib.c b/test/Driver/nodefaultlib.c index f9462fd27a..08bcea56fa 100644 --- a/test/Driver/nodefaultlib.c +++ b/test/Driver/nodefaultlib.c @@ -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++"