blob: 0be873f751054b823c42d7a4915d1ea29f612638 [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{{$}}
Heejin Ahnef9d6ae2019-03-05 20:35:34 +000052; CHECK-NEXT: i32.eqz $push4=, $pop3
53; CHECK-NEXT: br_if 0, $pop4
Sam Cleggbafe6902017-12-15 00:17:10 +000054; CHECK-NEXT: unreachable
Heejin Ahnef9d6ae2019-03-05 20:35:34 +000055; CHECK: end_block
Sam Cleggbafe6902017-12-15 00:17:10 +000056
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{{$}}
Heejin Ahnef9d6ae2019-03-05 20:35:34 +000068; CHECK-NEXT: i32.eqz $push4=, $pop3
69; CHECK-NEXT: br_if 0, $pop4
Sam Cleggbafe6902017-12-15 00:17:10 +000070; CHECK-NEXT: unreachable
Heejin Ahnef9d6ae2019-03-05 20:35:34 +000071; CHECK: end_block
Sam Cleggbafe6902017-12-15 00:17:10 +000072
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{{$}}
Heejin Ahnef9d6ae2019-03-05 20:35:34 +000083; CHECK-NEXT: i32.eqz $push4=, $pop3
84; CHECK-NEXT: br_if 0, $pop4
Sam Cleggbafe6902017-12-15 00:17:10 +000085; CHECK-NEXT: unreachable
86
87; CHECK-LABEL: .Lcall_dtors.1.associated1c1:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000088; CHECK-NEXT: .functype .Lcall_dtors.1.associated1c1 (i32) -> (){{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +000089; CHECK-NEXT: call orig_dtor1c1a{{$}}
90; CHECK-NEXT: call orig_dtor1c1b{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000091
92; CHECK-LABEL: .Lregister_call_dtors.1.associated1c1:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000093; CHECK: block
Sam Clegg275d15e2019-02-23 00:07:39 +000094; CHECK-NEXT: i32.const $push2=, .Lcall_dtors.1.associated1c1{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +000095; CHECK-NEXT: i32.const $push1=, 0
96; CHECK-NEXT: i32.const $push0=, __dso_handle
Sam Clegg275d15e2019-02-23 00:07:39 +000097; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
Heejin Ahnef9d6ae2019-03-05 20:35:34 +000098; CHECK-NEXT: i32.eqz $push4=, $pop3
99; CHECK-NEXT: br_if 0, $pop4
Sam Cleggbafe6902017-12-15 00:17:10 +0000100; CHECK-NEXT: unreachable
101
102; CHECK-LABEL: .Lcall_dtors:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000103; CHECK-NEXT: .functype .Lcall_dtors (i32) -> (){{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +0000104; CHECK-NEXT: call orig_dtor65536{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000105
106; CHECK-LABEL: .Lregister_call_dtors:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000107; CHECK: block
Sam Clegg275d15e2019-02-23 00:07:39 +0000108; CHECK-NEXT: i32.const $push2=, .Lcall_dtors{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000109; CHECK-NEXT: i32.const $push1=, 0
110; CHECK-NEXT: i32.const $push0=, __dso_handle
Sam Clegg275d15e2019-02-23 00:07:39 +0000111; CHECK-NEXT: i32.call $push3=, __cxa_atexit, $pop2, $pop1, $pop0{{$}}
Heejin Ahnef9d6ae2019-03-05 20:35:34 +0000112; CHECK-NEXT: i32.eqz $push4=, $pop3
113; CHECK-NEXT: br_if 0, $pop4
Sam Cleggbafe6902017-12-15 00:17:10 +0000114; CHECK-NEXT: unreachable
115
116; CHECK-LABEL: .section .init_array.0,"",@
Sam Clegg275d15e2019-02-23 00:07:39 +0000117; CHECK: .int32 .Lregister_call_dtors.0{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000118; CHECK-LABEL: .section .init_array.1,"",@
Sam Clegg275d15e2019-02-23 00:07:39 +0000119; CHECK: .int32 .Lregister_call_dtors.1{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000120; CHECK-LABEL: .section .init_array.200,"",@
Sam Clegg275d15e2019-02-23 00:07:39 +0000121; CHECK: .int32 orig_ctor{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000122; CHECK-LABEL: .section .init_array,"",@
Sam Clegg275d15e2019-02-23 00:07:39 +0000123; CHECK: .int32 .Lregister_call_dtors{{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000124
125; CHECK-LABEL: .weak __dso_handle
126
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000127; CHECK-LABEL: .functype __cxa_atexit (i32, i32, i32) -> (i32){{$}}
Sam Cleggbafe6902017-12-15 00:17:10 +0000128
129; We shouldn't make use of a .fini_array section.
130
131; FINI-NOT: fini_array
132
133; This function is listed after the null terminator, so it should
134; be excluded.
135
136; NULL-NOT: after_the_null