1 ; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck --check-prefix=CHECK --check-prefix=FINI --check-prefix=NULL %s
3 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
4 target triple = "wasm32-unknown-unknown"
6 ; Test that @llvm.global_dtors is properly lowered into @llvm.global_ctors,
7 ; grouping dtor calls by priority and associated symbol.
9 declare void @orig_ctor()
10 declare void @orig_dtor0()
11 declare void @orig_dtor1a()
12 declare void @orig_dtor1b()
13 declare void @orig_dtor1c0()
14 declare void @orig_dtor1c1a()
15 declare void @orig_dtor1c1b()
16 declare void @orig_dtor65536()
17 declare void @after_the_null()
19 @associated1c0 = external global i8
20 @associated1c1 = external global i8
22 @llvm.global_ctors = appending global
23 [1 x { i32, void ()*, i8* }]
25 { i32, void ()*, i8* } { i32 200, void ()* @orig_ctor, i8* null }
28 @llvm.global_dtors = appending global
29 [9 x { i32, void ()*, i8* }]
31 { i32, void ()*, i8* } { i32 0, void ()* @orig_dtor0, i8* null },
32 { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1a, i8* null },
33 { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1b, i8* null },
34 { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c0, i8* @associated1c0 },
35 { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c1a, i8* @associated1c1 },
36 { i32, void ()*, i8* } { i32 1, void ()* @orig_dtor1c1b, i8* @associated1c1 },
37 { i32, void ()*, i8* } { i32 65535, void ()* @orig_dtor65536, i8* null },
38 { i32, void ()*, i8* } { i32 65535, void ()* null, i8* null },
39 { i32, void ()*, i8* } { i32 65535, void ()* @after_the_null, i8* null }
42 ; CHECK-LABEL: .Lcall_dtors.0:
43 ; CHECK-NEXT: .functype .Lcall_dtors.0 (i32) -> (){{$}}
44 ; CHECK-NEXT: call orig_dtor0{{$}}
46 ; CHECK-LABEL: .Lregister_call_dtors.0:
48 ; CHECK-NEXT: i32.const $push2=, .Lcall_dtors.0{{$}}
49 ; CHECK-NEXT: i32.const $push1=, 0
50 ; CHECK-NEXT: i32.const $push0=, __dso_handle
51 ; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
52 ; CHECK-NEXT: i32.eqz $push4=, $pop3
53 ; CHECK-NEXT: br_if 0, $pop4
54 ; CHECK-NEXT: unreachable
57 ; CHECK-LABEL: .Lcall_dtors.1:
58 ; CHECK-NEXT: .functype .Lcall_dtors.1 (i32) -> (){{$}}
59 ; CHECK-NEXT: call orig_dtor1a{{$}}
60 ; CHECK-NEXT: call orig_dtor1b{{$}}
62 ; CHECK-LABEL: .Lregister_call_dtors.1:
64 ; CHECK-NEXT: i32.const $push2=, .Lcall_dtors.1{{$}}
65 ; CHECK-NEXT: i32.const $push1=, 0
66 ; CHECK-NEXT: i32.const $push0=, __dso_handle
67 ; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
68 ; CHECK-NEXT: i32.eqz $push4=, $pop3
69 ; CHECK-NEXT: br_if 0, $pop4
70 ; CHECK-NEXT: unreachable
73 ; CHECK-LABEL: .Lcall_dtors.1.associated1c0:
74 ; CHECK-NEXT: .functype .Lcall_dtors.1.associated1c0 (i32) -> (){{$}}
75 ; CHECK-NEXT: call orig_dtor1c0{{$}}
77 ; CHECK-LABEL: .Lregister_call_dtors.1.associated1c0:
79 ; CHECK-NEXT: i32.const $push2=, .Lcall_dtors.1.associated1c0{{$}}
80 ; CHECK-NEXT: i32.const $push1=, 0
81 ; CHECK-NEXT: i32.const $push0=, __dso_handle
82 ; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
83 ; CHECK-NEXT: i32.eqz $push4=, $pop3
84 ; CHECK-NEXT: br_if 0, $pop4
85 ; CHECK-NEXT: unreachable
87 ; CHECK-LABEL: .Lcall_dtors.1.associated1c1:
88 ; CHECK-NEXT: .functype .Lcall_dtors.1.associated1c1 (i32) -> (){{$}}
89 ; CHECK-NEXT: call orig_dtor1c1a{{$}}
90 ; CHECK-NEXT: call orig_dtor1c1b{{$}}
92 ; CHECK-LABEL: .Lregister_call_dtors.1.associated1c1:
94 ; CHECK-NEXT: i32.const $push2=, .Lcall_dtors.1.associated1c1{{$}}
95 ; CHECK-NEXT: i32.const $push1=, 0
96 ; CHECK-NEXT: i32.const $push0=, __dso_handle
97 ; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
98 ; CHECK-NEXT: i32.eqz $push4=, $pop3
99 ; CHECK-NEXT: br_if 0, $pop4
100 ; CHECK-NEXT: unreachable
102 ; CHECK-LABEL: .Lcall_dtors:
103 ; CHECK-NEXT: .functype .Lcall_dtors (i32) -> (){{$}}
104 ; CHECK-NEXT: call orig_dtor65536{{$}}
106 ; CHECK-LABEL: .Lregister_call_dtors:
108 ; CHECK-NEXT: i32.const $push2=, .Lcall_dtors{{$}}
109 ; CHECK-NEXT: i32.const $push1=, 0
110 ; CHECK-NEXT: i32.const $push0=, __dso_handle
111 ; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
112 ; CHECK-NEXT: i32.eqz $push4=, $pop3
113 ; CHECK-NEXT: br_if 0, $pop4
114 ; CHECK-NEXT: unreachable
116 ; CHECK-LABEL: .section .init_array.0,"",@
117 ; CHECK: .int32 .Lregister_call_dtors.0{{$}}
118 ; CHECK-LABEL: .section .init_array.1,"",@
119 ; CHECK: .int32 .Lregister_call_dtors.1{{$}}
120 ; CHECK-LABEL: .section .init_array.200,"",@
121 ; CHECK: .int32 orig_ctor{{$}}
122 ; CHECK-LABEL: .section .init_array,"",@
123 ; CHECK: .int32 .Lregister_call_dtors{{$}}
125 ; CHECK-LABEL: .weak __dso_handle
127 ; CHECK-LABEL: .functype __cxa_atexit (i32, i32, i32) -> (i32){{$}}
129 ; We shouldn't make use of a .fini_array section.
131 ; FINI-NOT: fini_array
133 ; This function is listed after the null terminator, so it should
136 ; NULL-NOT: after_the_null