Clang Project

clang_source_code/test/CodeGen/ifunc.c
1// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
2// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -O2 -emit-llvm -o - %s | FileCheck %s
3
4int foo(int) __attribute__ ((ifunc("foo_ifunc")));
5
6static int f1(int i) {
7  return i + 1;
8}
9
10static int f2(int i) {
11  return i + 2;
12}
13
14typedef int (*foo_t)(int);
15
16int global;
17
18static foo_t foo_ifunc() {
19  return global ? f1 : f2;
20}
21
22int bar() {
23  return foo(1);
24}
25
26extern void goo(void);
27
28void bar2(void) {
29  goo();
30}
31
32extern void goo(void) __attribute__ ((ifunc("goo_ifunc")));
33
34void* goo_ifunc(void) {
35  return 0;
36}
37// CHECK: @foo = ifunc i32 (i32), bitcast (i32 (i32)* ()* @foo_ifunc to i32 (i32)*)
38// CHECK: @goo = ifunc void (), bitcast (i8* ()* @goo_ifunc to void ()*)
39
40// CHECK: call i32 @foo(i32
41// CHECK: call void @goo()
42