Skip to content

Commit a04b470

Browse files
committed
Extend to benefit -gsplit-dwarf as well
1 parent ed6071d commit a04b470

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,15 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
10681068
}
10691069
}
10701070

1071-
if (Args.hasArg(options::OPT_gsplit_dwarf))
1071+
if (Args.hasArg(options::OPT_gsplit_dwarf)) {
1072+
StringRef F;
1073+
if (const Arg *A = Args.getLastArg(options::OPT_foutput_file_base))
1074+
F = A->getValue();
1075+
else
1076+
F = Output.getFilename();
10721077
CmdArgs.push_back(Args.MakeArgString(
1073-
Twine(PluginOptPrefix) + "dwo_dir=" + Output.getFilename() + "_dwo"));
1078+
Twine(PluginOptPrefix) + "dwo_dir=" + F + "_dwo"));
1079+
}
10741080

10751081
if (IsThinLTO && !IsOSAIX)
10761082
CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + "thinlto"));

clang/test/Driver/opt-record.c

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,40 @@
7979

8080
// CHECK-PASS-AUTO: "-plugin-opt=opt-remarks-hotness-threshold=auto"
8181

82-
// Check -foutput-file-base effect on -foptimization-record-file.
83-
// RUN: %clang --target=x86_64-linux -### -fuse-ld=lld -B%S/Inputs/lld -flto -fsave-optimization-record -foutput-file-base=/dir/file.ext %s 2>&1 | FileCheck %s -check-prefix=CHECK-BASE
84-
// RUN: %clang --target=x86_64-linux -### -o FOO -fuse-ld=lld -B%S/Inputs/lld -flto -fsave-optimization-record -foutput-file-base=/dir/file.ext %s 2>&1 | FileCheck %s -check-prefix=CHECK-BASE
85-
// RUN: %clang --target=x86_64-linux -### -fuse-ld=lld -B%S/Inputs/lld -flto -fsave-optimization-record -foptimization-record-file=user-file.ext -foutput-file-base=/dir/file.ext %s 2>&1 | FileCheck %s -check-prefix=CHECK-IGNORE-BASE
86-
87-
// CHECK-BASE: "-plugin-opt=opt-remarks-filename=/dir/file.ext.opt.ld.yaml"
88-
// CHECK-BASE-SAME: "-plugin-opt=opt-remarks-format=yaml"
89-
90-
// CHECK-IGNORE-BASE: "-plugin-opt=opt-remarks-filename=user-file.ext.opt.ld.yaml"
91-
// CHECK-IGNORE-BASE-SAME: "-plugin-opt=opt-remarks-format=yaml"
82+
// Check -foutput-file-base effect on -foptimization-record-file and
83+
// -gsplit-dwarf.
84+
//
85+
// DEFINE: %{RUN-BASE} = \
86+
// DEFINE: %clang --target=x86_64-linux -### -fuse-ld=lld -B%S/Inputs/lld \
87+
// DEFINE: -flto -fsave-optimization-record -gsplit-dwarf %s
88+
//
89+
// RUN: %{RUN-BASE} 2>&1 | FileCheck %s -check-prefix=CHECK-BASE-NONE
90+
//
91+
// RUN: %{RUN-BASE} -o FOO 2>&1 | FileCheck %s -check-prefix=CHECK-BASE-O
92+
//
93+
// RUN: %{RUN-BASE} -foutput-file-base=/dir/file.ext 2>&1 | \
94+
// RUN: FileCheck %s -check-prefix=CHECK-BASE
95+
//
96+
// RUN: %{RUN-BASE} -o FOO -foutput-file-base=/dir/file.ext 2>&1 | \
97+
// RUN: FileCheck %s -check-prefix=CHECK-BASE
98+
//
99+
// There is currently no option to ignore -foutput-file-base in the case of
100+
// -gsplit-dwarf.
101+
// RUN: %{RUN-BASE} -foutput-file-base=/dir/file.ext \
102+
// RUN: -foptimization-record-file=user-file.ext 2>&1 | \
103+
// RUN: FileCheck %s -check-prefix=CHECK-BASE-IGNORE
104+
//
105+
// CHECK-BASE-NONE: "-plugin-opt=dwo_dir=a.out_dwo"
106+
// CHECK-BASE-NONE-SAME: "-plugin-opt=opt-remarks-filename=a.out.opt.ld.yaml"
107+
// CHECK-BASE-NONE-SAME: "-plugin-opt=opt-remarks-format=yaml"
108+
//
109+
// CHECK-BASE-O: "-plugin-opt=dwo_dir=FOO_dwo"
110+
// CHECK-BASE-O-SAME: "-plugin-opt=opt-remarks-filename=FOO.opt.ld.yaml"
111+
// CHECK-BASE-O-SAME: "-plugin-opt=opt-remarks-format=yaml"
112+
//
113+
// CHECK-BASE: "-plugin-opt=dwo_dir=/dir/file.ext_dwo"
114+
// CHECK-BASE-SAME: "-plugin-opt=opt-remarks-filename=/dir/file.ext.opt.ld.yaml"
115+
// CHECK-BASE-SAME: "-plugin-opt=opt-remarks-format=yaml"
116+
//
117+
// CHECK-BASE-IGNORE: "-plugin-opt=opt-remarks-filename=user-file.ext.opt.ld.yaml"
118+
// CHECK-BASE-IGNORE-SAME: "-plugin-opt=opt-remarks-format=yaml"

0 commit comments

Comments
 (0)