1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=cfi-icall -o - %s | FileCheck %s 2 3 #if !__has_builtin(__builtin_function_start) 4 #error "missing __builtin_function_start" 5 #endif 6 7 void a(void) {} 8 // CHECK: @e = global i8* bitcast (void ()* no_cfi @_Z1av to i8*) 9 const void *e = __builtin_function_start(a); 10 11 constexpr void (*d)() = &a; 12 // CHECK: @f = global i8* bitcast (void ()* no_cfi @_Z1av to i8*) 13 const void *f = __builtin_function_start(d); 14 15 void b(void) {} 16 // CHECK: @g = global [2 x i8*] [i8* bitcast (void ()* @_Z1bv to i8*), i8* bitcast (void ()* no_cfi @_Z1bv to i8*)] 17 void *g[] = {(void *)b, __builtin_function_start(b)}; 18 19 void c(void *p) {} 20 21 class A { 22 public: 23 void f(); 24 virtual void g(); 25 static void h(); 26 int i() const; 27 int i(int n) const; 28 }; 29 30 void A::f() {} 31 void A::g() {} 32 void A::h() {} 33 34 // CHECK: define {{.*}}i32 @_ZNK1A1iEv(%class.A* {{.*}}%this) 35 int A::i() const { return 0; } 36 37 // CHECK: define {{.*}}i32 @_ZNK1A1iEi(%class.A* noundef {{.*}}%this, i32 noundef %n) 38 int A::i(int n) const { return 0; } 39 40 void h(void) { 41 // CHECK: store i8* bitcast (void ()* no_cfi @_Z1bv to i8*), i8** %g 42 void *g = __builtin_function_start(b); 43 // CHECK: call void @_Z1cPv(i8* noundef bitcast (void ()* no_cfi @_Z1av to i8*)) 44 c(__builtin_function_start(a)); 45 46 // CHECK: store i8* bitcast (void (%class.A*)* no_cfi @_ZN1A1fEv to i8*), i8** %Af 47 void *Af = __builtin_function_start(&A::f); 48 // CHECK: store i8* bitcast (void (%class.A*)* no_cfi @_ZN1A1gEv to i8*), i8** %Ag 49 void *Ag = __builtin_function_start(&A::g); 50 // CHECK: store i8* bitcast (void ()* no_cfi @_ZN1A1hEv to i8*), i8** %Ah 51 void *Ah = __builtin_function_start(&A::h); 52 // CHECK: store i8* bitcast (i32 (%class.A*)* no_cfi @_ZNK1A1iEv to i8*), i8** %Ai1 53 void *Ai1 = __builtin_function_start((int(A::*)() const) & A::i); 54 // CHECK: store i8* bitcast (i32 (%class.A*, i32)* no_cfi @_ZNK1A1iEi to i8*), i8** %Ai2 55 void *Ai2 = __builtin_function_start((int(A::*)(int) const) & A::i); 56 } 57