Skip to content

Commit d51dd89

Browse files
authored
[Driver][LTO] Copy fix empty stats filename to AIX (#71738)
copy implement of #71359 to AIX.cpp and add test scenario --------- Co-authored-by: zhijian <[email protected]>
1 parent b008d66 commit d51dd89

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Driver/ToolChains/AIX.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,15 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
233233

234234
if (D.isUsingLTO()) {
235235
assert(!Inputs.empty() && "Must have at least one input.");
236-
addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
236+
// Find the first filename InputInfo object.
237+
auto Input = llvm::find_if(
238+
Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
239+
if (Input == Inputs.end())
240+
// For a very rare case, all of the inputs to the linker are
241+
// InputArg. If that happens, just use the first InputInfo.
242+
Input = Inputs.begin();
243+
244+
addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
237245
D.getLTOMode() == LTOK_Thin);
238246
}
239247

clang/test/Driver/save-stats.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
// CHECK-LTO: "-o" "obj/dir{{/|\\\\}}save-stats.exe"
3333
// CHECK-LTO: "-plugin-opt=stats-file=save-stats.stats"
3434

35+
36+
// RUN: %clang --target=powerpc-unknown-aix -save-stats -flto -o obj/dir/save-stats %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-AIX-LTO
37+
// RUN: %clang --target=powerpc-unknown-aix -save-stats -flto -o obj/dir/save-stats -Wl,-bplugin-opt:-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-AIX-LTO
38+
39+
// CHECK-AIX-LTO: "-stats-file=save-stats.stats"
40+
// CHECK-AIX-LTO: "-o" "obj/dir{{/|\\\\}}save-stats"
41+
// CHECK-AIX-LTO: "-bplugin_opt:stats-file=save-stats.stats"
42+
3543
// RUN: %clang --target=x86_64-unknown-linux -save-stats=obj -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO-OBJ
3644
// CHECK-LTO-OBJ: "-plugin-opt=stats-file=obj/dir{{/|\\\\}}save-stats.stats"
3745

0 commit comments

Comments
 (0)