1 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=WITHOUTATEXIT %s 2 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin -fregister-global-dtors-with-atexit -debug-info-kind=line-tables-only -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=CXAATEXIT --check-prefix=WITHATEXIT %s 3 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin -fno-use-cxa-atexit -fregister-global-dtors-with-atexit -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ATEXIT --check-prefix=WITHATEXIT %s 4 5 // WITHOUTATEXIT: global_ctors{{.*}}@A{{.*}}@C 6 // WITHOUTATEXIT: @llvm.global_dtors = appending global [5 x { i32, void ()*, i8* }]{{.*}}@B{{.*}}@E{{.*}}@F{{.*}}@G{{.*}}@D 7 // WITHATEXIT: @llvm.global_ctors = appending global [5 x { i32, void ()*, i8* }]{{.*}}i32 65535, void ()* @A,{{.*}}i32 65535, void ()* @C,{{.*}}i32 123, void ()* @__GLOBAL_init_123,{{.*}}i32 789, void ()* @[[GLOBAL_INIT_789:__GLOBAL_init_789.[0-9]+]],{{.*}}i32 65535, void ()* @__GLOBAL_init_65535, 8 // WITHATEXIT-NOT: global_dtors 9 10 // CHECK: define{{.*}} void @A() 11 // CHECK: define{{.*}} void @B() 12 // CHECK: define internal void @E() 13 // CHECK: define internal void @F() 14 // CHECK: define internal void @G() 15 // CHECK: define{{.*}} i32 @__GLOBAL_init_789(i32 noundef %{{.*}}) 16 // CHECK: define internal void @C() 17 // CHECK: define internal i32 @foo() 18 // CHECK: define internal void @D() 19 // CHECK: define{{.*}} i32 @main() 20 // WITHOUTATEXIT-NOT: define 21 22 // CXAATEXIT: define internal void @__GLOBAL_init_123(){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions" !dbg ![[GLOBAL_INIT_SP:.*]] { 23 // ATEXIT: define internal void @__GLOBAL_init_123(){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions" 24 // CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @E to void (i8*)*), i8* null, i8* @__dso_handle) {{.*}}, !dbg ![[GLOBAL_INIT_LOC:.*]] 25 // CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @G to void (i8*)*), i8* null, i8* @__dso_handle) 26 // ATEXIT: call i32 @atexit(void ()* @E) 27 // ATEXIT: call i32 @atexit(void ()* @G) 28 29 // WITHATEXIT: define internal void @[[GLOBAL_INIT_789]](){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions" 30 // CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @F to void (i8*)*), i8* null, i8* @__dso_handle) 31 // ATEXIT: call i32 @atexit(void ()* @F) 32 33 // WITHATEXIT: define internal void @__GLOBAL_init_65535(){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions" 34 // CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @B to void (i8*)*), i8* null, i8* @__dso_handle) 35 // CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @D to void (i8*)*), i8* null, i8* @__dso_handle) 36 // ATEXIT: call i32 @atexit(void ()* @B) 37 // ATEXIT: call i32 @atexit(void ()* @D) 38 39 int printf(const char *, ...); 40 41 void A(void) __attribute__((constructor)); 42 void B(void) __attribute__((destructor)); 43 44 void A(void) { 45 printf("A\n"); 46 } 47 48 void B(void) { 49 printf("B\n"); 50 } 51 52 static void C(void) __attribute__((constructor)); 53 54 static void D(void) __attribute__((destructor)); 55 56 static __attribute__((destructor(123))) void E(void) { 57 } 58 59 static __attribute__((destructor(789))) void F(void) { 60 } 61 62 static __attribute__((destructor(123))) void G(void) { 63 } 64 65 // Test that this function doesn't collide with the synthesized constructor 66 // function for destructors with priority 789. 67 int __GLOBAL_init_789(int a) { 68 return a * a; 69 } 70 71 static int foo(void) { 72 return 10; 73 } 74 75 static void C(void) { 76 printf("A: %d\n", foo()); 77 } 78 79 static void D(void) { 80 printf("B\n"); 81 } 82 83 int main(void) { 84 return 0; 85 } 86 87 // CXAATEXIT: ![[GLOBAL_INIT_SP]] = distinct !DISubprogram(linkageName: "__GLOBAL_init_123", 88 // CXAATEXIT: ![[GLOBAL_INIT_LOC]] = !DILocation(line: 0, scope: ![[GLOBAL_INIT_SP]]) 89