Skip to content

Conversation

bader
Copy link
Contributor

@bader bader commented Oct 10, 2025

clang -flto -funified-lto -save-temps test.c

Fails with the following error message:

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.

> 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.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Oct 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Alexey Bader (bader)

Changes

> clang -flto -funified-lto -save-temps test.c

Fails with the following error message:

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.


Full diff: https://github.com/llvm/llvm-project/pull/162763.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/BackendUtil.cpp (+2-1)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 2d959827d6972..d28d886b3551e 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1199,7 +1199,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
       }
     }
 
-    if (shouldEmitUnifiedLTOModueFlag())
+    if (shouldEmitUnifiedLTOModueFlag() &&
+        !TheModule->getModuleFlag("UnifiedLTO"))
       TheModule->addModuleFlag(llvm::Module::Error, "UnifiedLTO", uint32_t(1));
   }
 

@bader bader requested a review from david-greene-cb October 10, 2025 02:50
@bader
Copy link
Contributor Author

bader commented Oct 10, 2025

The fix is similar to 53adfa8.

@bader bader changed the title Fix use of funified-lto and save-temps flags together [Clang][LTO] Fix use of funified-lto and save-temps flags together Oct 10, 2025
@bader bader requested a review from teresajohnson October 14, 2025 21:50
@bader
Copy link
Contributor Author

bader commented Oct 14, 2025

@david-greene-cb, GitHub account seems to be inactive.
@teresajohnson, since you reviewed 53adfa8, could you take a look at this change, please?

@efriedma-quic efriedma-quic requested review from ilovepi and removed request for david-greene-cb October 14, 2025 22:42
Copy link
Contributor

@ilovepi ilovepi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@bader bader merged commit 4a44f03 into llvm:main Oct 15, 2025
10 checks passed
@bader bader deleted the unified-lto-fix branch October 15, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants