xref: /llvm-project/clang/test/CodeGen/ptrauth-function-init.c (revision e23250ecb7e09170e584db60375100790f39fac9)
1 // RUN: %clang_cc1 %s       -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s
2 // RUN: %clang_cc1 %s       -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s
3 // RUN: %clang_cc1 -xc++ %s -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,CXX
4 // RUN: %clang_cc1 -xc++ %s -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,CXX
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 void f(void);
11 
12 #ifdef __cplusplus
13 
14 // CXX: define {{(dso_local )?}}internal void @__cxx_global_var_init()
15 // CXX: store ptr getelementptr inbounds (i32, ptr ptrauth (ptr @f, i32 0), i64 2), ptr @_ZL2fp, align 8
16 
17 // This is rejected in C mode as adding a non-zero constant to a signed pointer
18 // is unrepresentable in relocations. In C++ mode, this can be done dynamically
19 // by the global constructor.
20 __attribute__((used))
21 void (*const fp)(void) = (void (*)(void))((int *)&f + 2);
22 
23 #endif
24 
25 // CHECK: define {{(dso_local )?}}void @t1()
t1()26 void t1() {
27   // CHECK: [[PF:%.*]] = alloca ptr
28   // CHECK: store ptr getelementptr inbounds (i32, ptr ptrauth (ptr @f, i32 0), i64 2), ptr [[PF]]
29 
30   void (*pf)(void) = (void (*)(void))((int *)&f + 2);
31   (void)pf;
32 }
33 
34 #ifdef __cplusplus
35 }
36 #endif
37