Skip to content

Commit 1881832

Browse files
authored
[Driver][LTO] Copy fix empty stats filename to AVR, FreeBSD, Fuchsia (#71359)
Copy 85451f4 over to AVR, FreeBSD and Fuchsia.
1 parent 17db462 commit 1881832

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

clang/lib/Driver/ToolChains/AVR.cpp

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

514514
if (D.isUsingLTO()) {
515515
assert(!Inputs.empty() && "Must have at least one input.");
516-
addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
516+
// Find the first filename InputInfo object.
517+
auto Input = llvm::find_if(
518+
Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
519+
if (Input == Inputs.end())
520+
// For a very rare case, all of the inputs to the linker are
521+
// InputArg. If that happens, just use the first InputInfo.
522+
Input = Inputs.begin();
523+
524+
addLTOOptions(TC, Args, CmdArgs, Output, *Input,
517525
D.getLTOMode() == LTOK_Thin);
518526
}
519527

clang/lib/Driver/ToolChains/FreeBSD.cpp

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

265265
if (D.isUsingLTO()) {
266266
assert(!Inputs.empty() && "Must have at least one input.");
267-
addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
267+
// Find the first filename InputInfo object.
268+
auto Input = llvm::find_if(
269+
Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
270+
if (Input == Inputs.end())
271+
// For a very rare case, all of the inputs to the linker are
272+
// InputArg. If that happens, just use the first InputInfo.
273+
Input = Inputs.begin();
274+
275+
addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
268276
D.getLTOMode() == LTOK_Thin);
269277
}
270278

clang/lib/Driver/ToolChains/Fuchsia.cpp

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

139139
if (D.isUsingLTO()) {
140140
assert(!Inputs.empty() && "Must have at least one input.");
141-
addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
141+
// Find the first filename InputInfo object.
142+
auto Input = llvm::find_if(
143+
Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
144+
if (Input == Inputs.end())
145+
// For a very rare case, all of the inputs to the linker are
146+
// InputArg. If that happens, just use the first InputInfo.
147+
Input = Inputs.begin();
148+
149+
addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
142150
D.getLTOMode() == LTOK_Thin);
143151
}
144152

clang/test/Driver/save-stats.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@
1919
// RUN: not %clang -target x86_64-apple-darwin -save-stats=bla -c %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID
2020
// CHECK-INVALID: invalid value 'bla' in '-save-stats=bla'
2121

22-
// RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
22+
// RUN: %clang --target=x86_64-unknown-linux -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
2323
// Previously `-plugin-opt=stats-file` would use empty filename if a linker flag (i.e. -Wl) is presented before any input filename.
24-
// RUN: %clang --target=x86_64-linux-unknown -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
24+
// RUN: %clang --target=x86_64-unknown-linux -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
25+
// RUN: %clang --target=x86_64-unknown-freebsd -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
26+
// RUN: %clang --target=x86_64-unknown-freebsd -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
27+
// RUN: %clang --target=x86_64-unknown-fuchsia -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
28+
// RUN: %clang --target=x86_64-unknown-fuchsia -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
29+
// RUN: %clang --target=avr -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
30+
// RUN: %clang --target=avr -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
2531
// CHECK-LTO: "-stats-file=save-stats.stats"
2632
// CHECK-LTO: "-o" "obj/dir{{/|\\\\}}save-stats.exe"
2733
// CHECK-LTO: "-plugin-opt=stats-file=save-stats.stats"
2834

29-
// RUN: %clang -target x86_64-linux-unknown -save-stats=obj -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO-OBJ
35+
// 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
3036
// CHECK-LTO-OBJ: "-plugin-opt=stats-file=obj/dir{{/|\\\\}}save-stats.stats"
3137

3238
// RUN: env CC_PRINT_INTERNAL_STAT=1 \

0 commit comments

Comments
 (0)