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
18 lines
674 B
C++
18 lines
674 B
C++
// REQUIRES: x86-registered-target
|
|
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -O0 -fmerge-functions -emit-llvm -o - -x c++ < %s | FileCheck %s
|
|
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -O1 -fmerge-functions -emit-llvm -o - -x c++ < %s | FileCheck %s
|
|
|
|
// Basic functionality test. Function merging doesn't kick in on functions that
|
|
// are too simple.
|
|
|
|
struct A {
|
|
virtual int f(int x, int *p) { return x ? *p : 1; }
|
|
virtual int g(int x, int *p) { return x ? *p : 1; }
|
|
} a;
|
|
|
|
// CHECK: define linkonce_odr noundef i32 @_ZN1A1gEiPi(
|
|
// CHECK: tail call noundef i32 @0(
|
|
|
|
// CHECK: define linkonce_odr noundef i32 @_ZN1A1fEiPi(
|
|
// CHECK: tail call noundef i32 @0(
|