Skip to content

Commit 62eb65b

Browse files
authored
[FatLTO] output of -ffat-lto-objects -S should be assembly. (#79041)
Fat lto with -c compiles to an object file with the IR embedded in a section of the object, the combination of fat-lto with -S should then produce an assembly file equivalent of that. The IR output can still be genreated by using both -S and -emit-llvm.
1 parent 9577806 commit 62eb65b

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4770,10 +4770,11 @@ Action *Driver::ConstructPhaseAction(
47704770
case phases::Backend: {
47714771
if (isUsingLTO() && TargetDeviceOffloadKind == Action::OFK_None) {
47724772
types::ID Output;
4773-
if (Args.hasArg(options::OPT_S))
4773+
if (Args.hasArg(options::OPT_ffat_lto_objects))
4774+
Output = Args.hasArg(options::OPT_emit_llvm) ? types::TY_LTO_IR
4775+
: types::TY_PP_Asm;
4776+
else if (Args.hasArg(options::OPT_S))
47744777
Output = types::TY_LTO_IR;
4775-
else if (Args.hasArg(options::OPT_ffat_lto_objects))
4776-
Output = types::TY_PP_Asm;
47774778
else
47784779
Output = types::TY_LTO_BC;
47794780
return C.MakeAction<BackendJobAction>(Input, Output);

clang/test/Driver/fat-lto-objects.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,27 @@
1212
// CHECK-CC-S-NOT: -emit-llvm
1313
// CHECK-CC-S-NOT: -ffat-lto-objects
1414

15-
/// When LTO is enabled, we expect LLVM IR output and -ffat-lto-objects to be passed to cc1.
15+
/// When fat LTO is enabled with -S, we expect asm output and -ffat-lto-objects to be passed to cc1.
1616
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-LTO
17-
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-LTO
1817
// CHECK-CC-S-LTO: -cc1
1918
// CHECK-CC-S-LTO-SAME: -funified-lto
20-
// CHECK-CC-S-LTO-SAME: -emit-llvm
19+
// CHECK-CC-S-NOT: -emit-llvm
2120
// CHECK-CC-S-LTO-SAME: -ffat-lto-objects
2221

22+
/// When fat LTO is enabled with -S and -emit-llvm, we expect IR output and -ffat-lto-objects to be passed to cc1.
23+
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-EL-LTO
24+
// CHECK-CC-S-EL-LTO: -cc1
25+
// CHECK-CC-S-EL-LTO-SAME: -funified-lto
26+
// CHECK-CC-S-EL-LTO-SAME: -emit-llvm
27+
// CHECK-CC-S-EL-LTO-SAME: -ffat-lto-objects
28+
29+
/// When fat LTO is enabled wihtout -S we expect native object output and -ffat-lto-object to be passed to cc1.
30+
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-C-LTO
31+
// CHECK-CC-C-LTO: -cc1
32+
// CHECK-CC-C-LTO: -funified-lto
33+
// CHECK-CC-C-LTO: -emit-obj
34+
// CHECK-CC-C-LTO: -ffat-lto-objects
35+
2336
/// Make sure we don't have a warning for -ffat-lto-objects being unused
2437
// RUN: %clang --target=x86_64-unknown-linux-gnu -ffat-lto-objects -fdriver-only -Werror -v %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-NOLTO
2538
// CHECK-CC-NOLTO: -cc1

0 commit comments

Comments
 (0)