Skip to content

Commit f75126e

Browse files
authored
[FreeBSD] Support -stdlib=libstdc++
The experimental-library-flag.cpp test was failing on FreeBSD builders, which turned to be caused by missing support for -stdlib=libcstdc++ (and just using a hardcoded libc++ in all cases). Simplify FreeBSD::AddCXXStdlibLibArgs() by deferring to the parent class and dealing with the FreeSBD < 14 profiling support as a special case. While touching the test file also drop the unnecessary `-o %t.o`. This is not needed since the RUN lines use -### and don't produce any output. Reviewed By: DimitryAndric, MaskRay Pull Request: #126302
1 parent b4f91b0 commit f75126e

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

clang/lib/Driver/ToolChains/FreeBSD.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,12 @@ void FreeBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
452452

453453
void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args,
454454
ArgStringList &CmdArgs) const {
455+
Generic_ELF::AddCXXStdlibLibArgs(Args, CmdArgs);
455456
unsigned Major = getTriple().getOSMajorVersion();
456-
bool Profiling = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14;
457-
458-
CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
459-
if (Args.hasArg(options::OPT_fexperimental_library))
460-
CmdArgs.push_back("-lc++experimental");
457+
bool SuffixedLib = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14;
458+
if (SuffixedLib && GetCXXStdlibType(Args) == CST_Libcxx)
459+
llvm::replace(CmdArgs, static_cast<const char *>("-lc++"),
460+
static_cast<const char *>("-lc++_p"));
461461
}
462462

463463
void FreeBSD::AddCudaIncludeArgs(const ArgList &DriverArgs,

clang/test/Driver/experimental-library-flag.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
// RUN: %clangxx -fexperimental-library -stdlib=libstdc++ -### %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIBSTDCXX %s
1010
// RUN: %clangxx -fexperimental-library -stdlib=libc++ -nostdlib++ -### %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-NOSTDLIB %s
1111

12+
/// The FreeBSD driver did not support -stdlib=libstdc++ previously, check that it does the right thing here.
13+
// RUN: %clangxx --target=x86_64-unknown-freebsd -fexperimental-library -stdlib=libc++ -### %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIBCXX %s
14+
// RUN: %clangxx --target=x86_64-unknown-freebsd -fexperimental-library -stdlib=libstdc++ -### %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIBSTDCXX %s
15+
// RUN: %clangxx --target=x86_64-unknown-freebsd -fexperimental-library -stdlib=libc++ -nostdlib++ -### %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-NOSTDLIB %s
16+
1217
// -fexperimental-library must be passed to CC1.
1318
// CHECK: -fexperimental-library
1419

clang/test/Driver/freebsd.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
// RUN: %clangxx %s -### -o %t.o --target=amd64-unknown-freebsd -stdlib=platform 2>&1 \
1+
// RUN: %clangxx %s -### --target=amd64-unknown-freebsd -stdlib=platform 2>&1 \
22
// RUN: | FileCheck --check-prefix=CHECK-DEFAULT %s
3-
// RUN: %clangxx %s -### -o %t.o --target=amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \
4-
// RUN: | FileCheck --check-prefix=CHECK-TEN %s
3+
// RUN: %clangxx %s -### --target=amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \
4+
// RUN: | FileCheck --check-prefix=CHECK-DEFAULT %s
5+
// RUN: %clangxx %s -### --target=amd64-unknown-freebsd -stdlib=libc++ 2>&1 \
6+
// RUN: | FileCheck --check-prefix=CHECK-DEFAULT %s
7+
// RUN: %clangxx %s -### --target=amd64-unknown-freebsd -stdlib=libstdc++ 2>&1 \
8+
// RUN: | FileCheck --check-prefix=CHECK-STDLIBCXX %s
59
// CHECK-DEFAULT: "-lc++" "-lm"
6-
// CHECK-TEN: "-lc++" "-lm"
10+
// CHECK-STDLIBCXX: "-lstdc++" "-lm"
711

8-
// RUN: %clangxx %s -### -pg -o %t.o --target=amd64-unknown-freebsd -stdlib=platform 2>&1 \
12+
// RUN: %clangxx %s -### -pg --target=amd64-unknown-freebsd -stdlib=platform 2>&1 \
913
// RUN: | FileCheck --check-prefix=CHECK-PG-DEFAULT %s
10-
// RUN: %clangxx %s -### -pg -o %t.o --target=amd64-unknown-freebsd14.0 -stdlib=platform 2>&1 \
14+
// RUN: %clangxx %s -### -pg --target=amd64-unknown-freebsd14.0 -stdlib=platform 2>&1 \
1115
// RUN: | FileCheck --check-prefix=CHECK-PG-FOURTEEN %s
12-
// RUN: %clangxx %s -### -pg -o %t.o --target=amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \
16+
// RUN: %clangxx %s -### -pg --target=amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \
1317
// RUN: | FileCheck --check-prefix=CHECK-PG-TEN %s
1418
// CHECK-PG-DEFAULT: "-lc++" "-lm"
1519
// CHECK-PG-FOURTEEN: "-lc++" "-lm"

0 commit comments

Comments
 (0)