brintos

brintos / llvm-project-archived public Read only

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