Skip to content

Commit

Permalink
[Driver] Also obey -nostdlib++ when rewriting -lstdc++.
Browse files Browse the repository at this point in the history
Reviewers: pirama

Reviewed By: pirama

Subscribers: cfe-commits

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

llvm-svn: 349570
  • Loading branch information
DanAlbert committed Dec 18, 2018
1 parent f03c45d commit f5ffa1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/Driver/Driver.cpp
Expand Up @@ -303,6 +303,7 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
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,
Expand Down Expand Up @@ -347,7 +348,8 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
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;
}
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Driver/nostdlibxx.cpp
Expand Up @@ -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++

0 comments on commit f5ffa1a

Please sign in to comment.