Debian Codegraph @

clang/test/CodeGen/ifunc.c

raw
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 // RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
4 // RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
5 // RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsanitize=memory -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
6 // RUN: %clang_cc1 -triple arm64-apple-macosx -emit-llvm -o - %s | FileCheck %s
7 // RUN: %clang_cc1 -triple x86_64-apple-macosx -emit-llvm -o - %s | FileCheck %s
8 // RUN: %clang_cc1 -triple arm64-apple-macosx -O2 -emit-llvm -o - %s | FileCheck %s
9 // RUN: %clang_cc1 -triple x86_64-apple-macosx -O2 -emit-llvm -o - %s | FileCheck %s
10 // RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
11 // RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
12 // RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
13 // RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
14
15 /// The ifunc is emitted before its resolver.
16 int foo(int) __attribute__ ((ifunc("foo_ifunc")));
17
18 static int f1(int i) {
19 return i + 1;
20 }
21
22 static int f2(int i) {
23 return i + 2;
24 }
25
26 typedef int (*foo_t)(int);
27
28 int global;
29
30 static foo_t foo_ifunc(void) {
31 return global ? f1 : f2;
32 }
33
34 int bar(void) {
35 return foo(1);
36 }
37
38 extern void goo(void);
39
40 void bar2(void) {
41 goo();
42 }
43
44 extern void goo(void) __attribute__ ((ifunc("goo_ifunc")));
45
46 void* goo_ifunc(void) {
47 return 0;
48 }
49
50 /// The ifunc is emitted after its resolver.
51 void *hoo_ifunc(void) { return 0; }
52 extern void hoo(int) __attribute__ ((ifunc("hoo_ifunc")));
53
54 // CHECK: @foo = ifunc i32 (i32), ptr @foo_ifunc
55 // CHECK: @goo = ifunc void (), ptr @goo_ifunc
56 // CHECK: @hoo = ifunc void (i32), ptr @hoo_ifunc
57
58 // CHECK: call i32 @foo(i32
59 // CHECK: call void @goo()
60
61 // SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @goo_ifunc() #[[#GOO_IFUNC:]] {
62
63 // SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @hoo_ifunc() #[[#GOO_IFUNC]] {
64
65 // SAN: define internal {{(noundef )?}}nonnull ptr @foo_ifunc() #[[#FOO_IFUNC:]] {
66
67 // SAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}
68 // SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}