Skip to content

Commit 4a44f03

Browse files
authored
[Clang][LTO] Fix use of funified-lto and save-temps flags together (#162763)
> clang -flto -funified-lto -save-temps test.c Fails with the following error message: ```bash module flag identifiers must be unique (or of 'require' type) !"UnifiedLTO" fatal error: error in backend: Broken module found, compilation aborted! clang: error: clang frontend command failed with exit code 70 (use -v to see invocation) ``` Here is what the driver does when `-save-temps` flag is set: > clang -flto -funified-lto -save-temps test.c -ccc-print-phases > +- 0: input, "test.c", c > +- 1: preprocessor, {0}, cpp-output > +- 2: compiler, {1}, ir > +- 3: backend, {2}, lto-bc > 4: linker, {3}, image The IR output of "compiler" step has "UnifiedLTO" module flag. "backend" step adds another module flag with "UnifiedLTO" identifier, which invalidates the LLVM IR module.
1 parent 995eb4c commit 4a44f03

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
12001200
}
12011201
}
12021202

1203-
if (shouldEmitUnifiedLTOModueFlag())
1203+
if (shouldEmitUnifiedLTOModueFlag() &&
1204+
!TheModule->getModuleFlag("UnifiedLTO"))
12041205
TheModule->addModuleFlag(llvm::Module::Error, "UnifiedLTO", uint32_t(1));
12051206
}
12061207

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; Test that we do not duplicate the UnifiedLTO module flag.
2+
;
3+
; RUN: %clang_cc1 -emit-llvm -flto=full -funified-lto -o - %s | FileCheck %s
4+
5+
; CHECK: !llvm.module.flags = !{!0, !1, !2, !3}
6+
!llvm.module.flags = !{!0, !1, !2, !3}
7+
8+
!0 = !{i32 1, !"wchar_size", i32 2}
9+
!1 = !{i32 7, !"frame-pointer", i32 2}
10+
!2 = !{i32 1, !"EnableSplitLTOUnit", i32 1}
11+
!3 = !{i32 1, !"UnifiedLTO", i32 1}

0 commit comments

Comments
 (0)