2016-04-11 15:48:59 +08:00
|
|
|
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
|
|
|
|
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -O2 -emit-llvm -o - %s | FileCheck %s
|
|
|
|
|
|
|
|
int foo(int) __attribute__ ((ifunc("foo_ifunc")));
|
|
|
|
|
|
|
|
static int f1(int i) {
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int f2(int i) {
|
|
|
|
return i + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef int (*foo_t)(int);
|
|
|
|
|
|
|
|
int global;
|
|
|
|
|
2022-02-16 05:06:01 +08:00
|
|
|
static foo_t foo_ifunc(void) {
|
2016-04-11 15:48:59 +08:00
|
|
|
return global ? f1 : f2;
|
|
|
|
}
|
|
|
|
|
2022-02-16 05:06:01 +08:00
|
|
|
int bar(void) {
|
2016-04-11 15:48:59 +08:00
|
|
|
return foo(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void goo(void);
|
|
|
|
|
|
|
|
void bar2(void) {
|
|
|
|
goo();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void goo(void) __attribute__ ((ifunc("goo_ifunc")));
|
|
|
|
|
|
|
|
void* goo_ifunc(void) {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-11-01 11:00:57 +08:00
|
|
|
// CHECK: @foo = ifunc i32 (i32), i32 (i32)* ()* @foo_ifunc
|
|
|
|
// CHECK: @goo = ifunc void (), bitcast (i8* ()* @goo_ifunc to void ()* ()*)
|
2016-04-11 15:48:59 +08:00
|
|
|
|
|
|
|
// CHECK: call i32 @foo(i32
|
|
|
|
// CHECK: call void @goo()
|