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