37 lines · c
1// RUN: %clang_cc1 %s -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s2// RUN: %clang_cc1 %s -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s3// RUN: %clang_cc1 -xc++ %s -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,CXX4// RUN: %clang_cc1 -xc++ %s -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,CXX5 6#ifdef __cplusplus7extern "C" {8#endif9 10void f(void);11 12#ifdef __cplusplus13 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 816 17// This is rejected in C mode as adding a non-zero constant to a signed pointer18// is unrepresentable in relocations. In C++ mode, this can be done dynamically19// by the global constructor.20__attribute__((used))21void (*const fp)(void) = (void (*)(void))((int *)&f + 2);22 23#endif24 25// CHECK: define {{(dso_local )?}}void @t1()26void t1() {27 // CHECK: [[PF:%.*]] = alloca ptr28 // 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 __cplusplus35}36#endif37