blob: 6429cd2344c1cd511b517691dec6da2171817025 [file] [log] [blame]
Wouter van Oortmerssen8a9cb242018-08-27 15:45:51 +00001; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck --check-prefix=CHECK --check-prefix=FINI --check-prefix=NULL %s
Sam Cleggbafe6902017-12-15 00:17:10 +00002
3target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Sam Clegga5908002018-05-10 17:49:11 +00004target triple = "wasm32-unknown-unknown"
Sam Cleggbafe6902017-12-15 00:17:10 +00005
6; Test that @llvm.global_dtors is properly lowered into @llvm.global_ctors,
7; grouping dtor calls by priority and associated symbol.
8
9declare void @orig_ctor()
10declare void @orig_dtor0()
11declare void @orig_dtor1a()
12declare void @orig_dtor1b()
13declare void @orig_dtor1c0()
14declare void @orig_dtor1c1a()
15declare void @orig_dtor1c1b()
16declare void @orig_dtor65536()
17declare void @after_the_null()
18
19@associated1c0 = external global i8
20@associated1c1 = external global i8
21
22@llvm.global_ctors = appending global
23[1 x { i32, void ()*, i8* }]
24[
25 { i32, void ()*, i8* } { i32 200, void ()* @orig_ctor, i8* null }
26]
27
28@llvm.global_dtors = appending global
29[9 x { i32, void ()*, i8* }]
30[
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 }
40]
41
42; CHECK-LABEL: .Lcall_dtors.0:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000043; CHECK-NEXT: .functype .Lcall_dtors.0 (i32) -> (){{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +000044; CHECK-NEXT: call orig_dtor0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000045
46; CHECK-LABEL: .Lregister_call_dtors.0:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000047; CHECK: block
Sam Clegg275d15e2019-02-23 00:07:39 +000048; CHECK-NEXT: i32.const $push2=, .Lcall_dtors.0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000049; CHECK-NEXT: i32.const $push1=, 0
50; CHECK-NEXT: i32.const $push0=, __dso_handle
Sam Clegg275d15e2019-02-23 00:07:39 +000051; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000052; CHECK-NEXT: br_if 0, $pop3
53; CHECK-NEXT: return
54; CHECK: end_block
55; CHECK-NEXT: unreachable
56
57; CHECK-LABEL: .Lcall_dtors.1:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000058; CHECK-NEXT: .functype .Lcall_dtors.1 (i32) -> (){{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +000059; CHECK-NEXT: call orig_dtor1a{{$}}
60; CHECK-NEXT: call orig_dtor1b{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000061
62; CHECK-LABEL: .Lregister_call_dtors.1:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000063; CHECK: block
Sam Clegg275d15e2019-02-23 00:07:39 +000064; CHECK-NEXT: i32.const $push2=, .Lcall_dtors.1{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000065; CHECK-NEXT: i32.const $push1=, 0
66; CHECK-NEXT: i32.const $push0=, __dso_handle
Sam Clegg275d15e2019-02-23 00:07:39 +000067; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000068; CHECK-NEXT: br_if 0, $pop3
69; CHECK-NEXT: return
70; CHECK: end_block
71; CHECK-NEXT: unreachable
72
73; CHECK-LABEL: .Lcall_dtors.1.associated1c0:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000074; CHECK-NEXT: .functype .Lcall_dtors.1.associated1c0 (i32) -> (){{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +000075; CHECK-NEXT: call orig_dtor1c0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000076
77; CHECK-LABEL: .Lregister_call_dtors.1.associated1c0:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000078; CHECK: block
Sam Clegg275d15e2019-02-23 00:07:39 +000079; CHECK-NEXT: i32.const $push2=, .Lcall_dtors.1.associated1c0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000080; CHECK-NEXT: i32.const $push1=, 0
81; CHECK-NEXT: i32.const $push0=, __dso_handle
Sam Clegg275d15e2019-02-23 00:07:39 +000082; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000083; CHECK-NEXT: br_if 0, $pop3
84; CHECK-NEXT: return
85; CHECK: end_block
86; CHECK-NEXT: unreachable
87
88; CHECK-LABEL: .Lcall_dtors.1.associated1c1:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000089; CHECK-NEXT: .functype .Lcall_dtors.1.associated1c1 (i32) -> (){{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +000090; CHECK-NEXT: call orig_dtor1c1a{{$}}
91; CHECK-NEXT: call orig_dtor1c1b{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000092
93; CHECK-LABEL: .Lregister_call_dtors.1.associated1c1:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000094; CHECK: block
Sam Clegg275d15e2019-02-23 00:07:39 +000095; CHECK-NEXT: i32.const $push2=, .Lcall_dtors.1.associated1c1{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000096; CHECK-NEXT: i32.const $push1=, 0
97; CHECK-NEXT: i32.const $push0=, __dso_handle
Sam Clegg275d15e2019-02-23 00:07:39 +000098; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000099; CHECK-NEXT: br_if 0, $pop3
100; CHECK-NEXT: return
101; CHECK: end_block
102; CHECK-NEXT: unreachable
103
104; CHECK-LABEL: .Lcall_dtors:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000105; CHECK-NEXT: .functype .Lcall_dtors (i32) -> (){{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +0000106; CHECK-NEXT: call orig_dtor65536{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000107
108; CHECK-LABEL: .Lregister_call_dtors:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000109; CHECK: block
Sam Clegg275d15e2019-02-23 00:07:39 +0000110; CHECK-NEXT: i32.const $push2=, .Lcall_dtors{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000111; CHECK-NEXT: i32.const $push1=, 0
112; CHECK-NEXT: i32.const $push0=, __dso_handle
Sam Clegg275d15e2019-02-23 00:07:39 +0000113; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000114; CHECK-NEXT: br_if 0, $pop3
115; CHECK-NEXT: return
116; CHECK: end_block
117; CHECK-NEXT: unreachable
118
119; CHECK-LABEL: .section .init_array.0,"",@
Sam Clegg275d15e2019-02-23 00:07:39 +0000120; CHECK: .int32 .Lregister_call_dtors.0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000121; CHECK-LABEL: .section .init_array.1,"",@
Sam Clegg275d15e2019-02-23 00:07:39 +0000122; CHECK: .int32 .Lregister_call_dtors.1{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000123; CHECK-LABEL: .section .init_array.200,"",@
Sam Clegg275d15e2019-02-23 00:07:39 +0000124; CHECK: .int32 orig_ctor{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000125; CHECK-LABEL: .section .init_array,"",@
Sam Clegg275d15e2019-02-23 00:07:39 +0000126; CHECK: .int32 .Lregister_call_dtors{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000127
128; CHECK-LABEL: .weak __dso_handle
129
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000130; CHECK-LABEL: .functype __cxa_atexit (i32, i32, i32) -> (i32){{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000131
132; We shouldn't make use of a .fini_array section.
133
134; FINI-NOT: fini_array
135
136; This function is listed after the null terminator, so it should
137; be excluded.
138
139; NULL-NOT: after_the_null