| Issue |
242262
|
| Summary |
[Linker] Min module flags are not zeroed when another input has no module flags
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
XFabian
|
llvm-link preserves a nonzero Min module flag when another input module has no !llvm.module.flags metadata. This appears inconsistent with the [LangRef](https://llvm.org/docs/LangRef.html#module-flags-metadata), which specifies that an absent flag contributes zero for Min.
Reproduced on LLVM main at c62690f9a7b2474368ff131510a25389d10d8c05 (LLVM 24.0.0git, assertions enabled), without any plugins.
This appears to be an edge case missed by [D129911](https://reviews.llvm.org/D129911), which introduced absent-flag handling. Its tests cover flags missing from individual modules, but both inputs still have module-flags metadata.
The attached min-flagless.ll is a standalone lit reproducer:
```llvm
; RUN: split-file %s %t
; RUN: llvm-link %t/flagged.ll %t/plain.ll -S -o - \
; RUN: | FileCheck %s --check-prefix=ZERO
; RUN: llvm-link %t/plain.ll %t/flagged.ll -S -o - \
; RUN: | FileCheck %s --check-prefix=ZERO
; ZERO: !{{[0-9]+}} = !{i32 8, !"test.min", i32 0}
;--- flagged.ll
define void @flagged() {
ret void
}
!llvm.module.flags = !{!0}
!0 = !{i32 8, !"test.min", i32 7}
;--- plain.ll
define void @plain() {
ret void
}
```
Run from the repository root:
build/bin/llvm-lit -sv llvm/test/Linker/min-flagless.ll
Expected merged flag:
!0 = !{i32 8, !"test.min", i32 0}
Actual:
!0 = !{i32 8, !"test.min", i32 7}
Both input orders exhibit the issue. Adding an unrelated module flag to the otherwise flagless input makes the result zero as expected.
I looked for the cause and found the early-return/copy paths in IRLinker::linkModuleFlagsMetadata(), which bypass the absent-Min handling.
One complication is distinguishing [synthetic empty destinations](https://github.com/llvm/llvm-project/blob/c62690f9a7b2474368ff131510a25389d10d8c05/llvm/tools/llvm-link/llvm-link.cpp#L479) used to initialize linking from a real input module that has no flags. On a synthetic module I guess the flag should be preserved while on real input module with no flags the flag should be made 0.
I’m happy to work on a fix. Would an explicit destination-initialization mode in IRMover, propagated through Linker, be an appropriate direction? Other callers, including the static helper, C API, and ThinLTO imports, would need consideration.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs