xref: /llvm-project/clang/test/CodeGenCXX/ptrauth-static-destructors.cpp (revision 8be1325cb1903797ba3dce67087e395f9e080576)
107f8a65dSOliver Hunt // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm -std=c++11 %s -o - \
207f8a65dSOliver Hunt // RUN:  | FileCheck %s --check-prefix=CXAATEXIT
307f8a65dSOliver Hunt 
407f8a65dSOliver Hunt // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm -std=c++11 %s -o - \
5*8be1325cSOliver Hunt // RUN:    -fno-use-cxa-atexit | FileCheck %s --check-prefixes=ATEXIT,ATEXIT_DARWIN
6a1d77caaSDaniil Kovalev 
7a1d77caaSDaniil Kovalev // RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -emit-llvm -std=c++11 %s -o - \
8a1d77caaSDaniil Kovalev // RUN:  | FileCheck %s --check-prefix=CXAATEXIT
9a1d77caaSDaniil Kovalev 
10a1d77caaSDaniil Kovalev // RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -emit-llvm -std=c++11 %s -o - \
11*8be1325cSOliver Hunt // RUN:    -fno-use-cxa-atexit | FileCheck %s --check-prefixes=ATEXIT,ATEXIT_ELF
12*8be1325cSOliver Hunt 
13*8be1325cSOliver Hunt // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm -std=c++11 %s \
14*8be1325cSOliver Hunt // RUN:  -fptrauth-function-pointer-type-discrimination  -o - | FileCheck %s --check-prefix=CXAATEXIT_DISC
15*8be1325cSOliver Hunt 
16*8be1325cSOliver Hunt // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm -std=c++11 %s -o - \
17*8be1325cSOliver Hunt // RUN:   -fptrauth-function-pointer-type-discrimination  -fno-use-cxa-atexit \
18*8be1325cSOliver Hunt // RUN:  | FileCheck %s --check-prefixes=ATEXIT_DISC,ATEXIT_DISC_DARWIN
19*8be1325cSOliver Hunt 
20*8be1325cSOliver Hunt // RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -emit-llvm -std=c++11 %s \
21*8be1325cSOliver Hunt // RUN:  -fptrauth-function-pointer-type-discrimination  -o - | FileCheck %s --check-prefix=CXAATEXIT_DISC
22*8be1325cSOliver Hunt 
23*8be1325cSOliver Hunt // RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -emit-llvm -std=c++11 %s -o - \
24*8be1325cSOliver Hunt // RUN:   -fptrauth-function-pointer-type-discrimination -fno-use-cxa-atexit \
25*8be1325cSOliver Hunt // RUN:  | FileCheck %s --check-prefixes=ATEXIT_DISC,ATEXIT_DISC_ELF
2607f8a65dSOliver Hunt 
2707f8a65dSOliver Hunt class Foo {
2807f8a65dSOliver Hunt  public:
2907f8a65dSOliver Hunt   ~Foo() {
3007f8a65dSOliver Hunt   }
3107f8a65dSOliver Hunt };
3207f8a65dSOliver Hunt 
3307f8a65dSOliver Hunt Foo global;
3407f8a65dSOliver Hunt 
3507f8a65dSOliver Hunt // CXAATEXIT: define internal void @__cxx_global_var_init()
3607f8a65dSOliver Hunt // CXAATEXIT:   call i32 @__cxa_atexit(ptr ptrauth (ptr @_ZN3FooD1Ev, i32 0), ptr @global, ptr @__dso_handle)
3707f8a65dSOliver Hunt 
38*8be1325cSOliver Hunt // CXAATEXIT_DISC: define internal void @__cxx_global_var_init()
39*8be1325cSOliver Hunt // CXAATEXIT_DISC:   call i32 @__cxa_atexit(ptr ptrauth (ptr @_ZN3FooD1Ev, i32 0, i64 10942), ptr @global, ptr @__dso_handle)
4007f8a65dSOliver Hunt 
4107f8a65dSOliver Hunt // ATEXIT: define internal void @__cxx_global_var_init()
4207f8a65dSOliver Hunt // ATEXIT:   %{{.*}} = call i32 @atexit(ptr ptrauth (ptr @__dtor_global, i32 0))
4307f8a65dSOliver Hunt 
44*8be1325cSOliver Hunt // ATEXIT_DARWIN: define internal void @__dtor_global() {{.*}} section "__TEXT,__StaticInit,regular,pure_instructions" {
45*8be1325cSOliver Hunt // ATEXIT_ELF:    define internal void @__dtor_global() {{.*}} section ".text.startup" {
46*8be1325cSOliver Hunt // ATEXIT_DARWIN:   %{{.*}} = call ptr @_ZN3FooD1Ev(ptr @global)
47*8be1325cSOliver Hunt // ATEXIT_ELF:      call void @_ZN3FooD1Ev(ptr @global)
48*8be1325cSOliver Hunt 
49*8be1325cSOliver Hunt // ATEXIT_DISC: define internal void @__cxx_global_var_init()
50*8be1325cSOliver Hunt // ATEXIT_DISC:   %{{.*}} = call i32 @atexit(ptr ptrauth (ptr @__dtor_global, i32 0, i64 10942))
51*8be1325cSOliver Hunt 
52*8be1325cSOliver Hunt 
53*8be1325cSOliver Hunt // ATEXIT_DISC_DARWIN: define internal void @__dtor_global() {{.*}} section "__TEXT,__StaticInit,regular,pure_instructions" {
54*8be1325cSOliver Hunt // ATEXIT_DISC_ELF:    define internal void @__dtor_global() {{.*}} section ".text.startup" {
55*8be1325cSOliver Hunt // ATEXIT_DISC_DARWIN:   %{{.*}} = call ptr @_ZN3FooD1Ev(ptr @global)
56*8be1325cSOliver Hunt // ATEXIT_DISC_ELF:      call void @_ZN3FooD1Ev(ptr @global)
57