Files
clang-p2996/llvm/test/Transforms/MergeFunc/comdat.ll
Florian Hahn f10e0f7321 [MergeFuncs] Don't introduce calls to (linkonce,weak)_odr functions. (#125050)
Avoid creating new calls to linkonce_odr/weak_odr functions when
merging 2 functions, as this may introduce an infinite call
cycle.

Consider 2 functions below, both present in 2 modules. 

Module X

--
define linkonce_odr void @"A"() {
  call void @"foo"()
}

define linkonce_odr void @"B"() {
  call void @"foo"()
}
--- 

Module Y
---
global @"g" = @"B"

define linkonce_odr void @"A"() {
  %l = load @"g"
  call void %l()
}

define linkonce_odr void @"B"() {
  call void @"foo"()
}
---

 @"A" and @"B" in both modules are semantically equivalent

Module X after function merging:

---
define linkonce_odr void @"A"() {
  call void @"foo"()
}

define linkonce_odr void @"B"() {
  call void @"A"()
}
---

Module Y is unchanged.

Then the linker picks @"A" from module Y and @"B" from module X. Now there's an infinite call cycle


PR: https://github.com/llvm/llvm-project/pull/125050
2025-02-25 15:55:25 +00:00

26 lines
664 B
LLVM

; RUN: opt -S -passes=mergefunc %s | FileCheck %s
@symbols = linkonce_odr global <{ ptr, ptr }> <{ ptr @f, ptr @g }>
$f = comdat any
$g = comdat any
define linkonce_odr hidden i32 @f(i32 %x, i32 %y) comdat {
%sum = add i32 %x, %y
%sum2 = add i32 %x, %sum
%sum3 = add i32 %x, %sum
ret i32 %sum3
}
define linkonce_odr hidden i32 @g(i32 %x, i32 %y) comdat {
%sum = add i32 %x, %y
%sum2 = add i32 %x, %sum
%sum3 = add i32 %x, %sum
ret i32 %sum3
}
; CHECK-DAG: define private i32 @0(i32 %x, i32 %y) comdat($f)
; CHECK-DAG: define linkonce_odr hidden i32 @g(i32 %0, i32 %1) comdat {
; CHECK-DAG: define linkonce_odr hidden i32 @f(i32 %0, i32 %1) {