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 
4 int foo(int) __attribute__ ((ifunc("foo_ifunc")));
5 
f1(int i)6 static int f1(int i) {
7   return i + 1;
8 }
9 
f2(int i)10 static int f2(int i) {
11   return i + 2;
12 }
13 
14 typedef int (*foo_t)(int);
15 
16 int global;
17 
foo_ifunc()18 static foo_t foo_ifunc() {
19   return global ? f1 : f2;
20 }
21 
bar()22 int bar() {
23   return foo(1);
24 }
25 
26 extern void goo(void);
27 
bar2(void)28 void bar2(void) {
29   goo();
30 }
31 
32 extern void goo(void) __attribute__ ((ifunc("goo_ifunc")));
33 
goo_ifunc(void)34 void* 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