File: constructor-attribute.c

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (88 lines) | stat: -rw-r--r-- 3,848 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=WITHOUTATEXIT %s
// 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
// 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

// WITHOUTATEXIT: global_ctors{{.*}}@A{{.*}}@C
// WITHOUTATEXIT: @llvm.global_dtors = appending global [5 x { i32, void ()*, i8* }]{{.*}}@B{{.*}}@E{{.*}}@F{{.*}}@G{{.*}}@D
// 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,
// WITHATEXIT-NOT: global_dtors

// CHECK: define{{.*}} void @A()
// CHECK: define{{.*}} void @B()
// CHECK: define internal void @E()
// CHECK: define internal void @F()
// CHECK: define internal void @G()
// CHECK: define{{.*}} i32 @__GLOBAL_init_789(i32 noundef %{{.*}})
// CHECK: define internal void @C()
// CHECK: define internal i32 @foo()
// CHECK: define internal void @D()
// CHECK: define{{.*}} i32 @main()
// WITHOUTATEXIT-NOT: define

// CXAATEXIT: define internal void @__GLOBAL_init_123(){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions" !dbg ![[GLOBAL_INIT_SP:.*]] {
// ATEXIT: define internal void @__GLOBAL_init_123(){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions"
// CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @E to void (i8*)*), i8* null, i8* @__dso_handle) {{.*}}, !dbg ![[GLOBAL_INIT_LOC:.*]]
// CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @G to void (i8*)*), i8* null, i8* @__dso_handle)
// ATEXIT: call i32 @atexit(void ()* @E)
// ATEXIT: call i32 @atexit(void ()* @G)

// WITHATEXIT: define internal void @[[GLOBAL_INIT_789]](){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions"
// CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @F to void (i8*)*), i8* null, i8* @__dso_handle)
// ATEXIT: call i32 @atexit(void ()* @F)

// WITHATEXIT: define internal void @__GLOBAL_init_65535(){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions"
// CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @B to void (i8*)*), i8* null, i8* @__dso_handle)
// CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @D to void (i8*)*), i8* null, i8* @__dso_handle)
// ATEXIT: call i32 @atexit(void ()* @B)
// ATEXIT: call i32 @atexit(void ()* @D)

int printf(const char *, ...);

void A(void) __attribute__((constructor));
void B(void) __attribute__((destructor));

void A(void) {
  printf("A\n");
}

void B(void) {
  printf("B\n");
}

static void C(void) __attribute__((constructor));

static void D(void) __attribute__((destructor));

static __attribute__((destructor(123))) void E(void) {
}

static __attribute__((destructor(789))) void F(void) {
}

static __attribute__((destructor(123))) void G(void) {
}

// Test that this function doesn't collide with the synthesized constructor
// function for destructors with priority 789.
int __GLOBAL_init_789(int a) {
  return a * a;
}

static int foo(void) {
  return 10;
}

static void C(void) {
  printf("A: %d\n", foo());
}

static void D(void) {
  printf("B\n");
}

int main(void) {
  return 0;
}

// CXAATEXIT: ![[GLOBAL_INIT_SP]] = distinct !DISubprogram(linkageName: "__GLOBAL_init_123",
// CXAATEXIT: ![[GLOBAL_INIT_LOC]] = !DILocation(line: 0, scope: ![[GLOBAL_INIT_SP]])