xref: /llvm-project/llvm/test/Transforms/GlobalOpt/atexit-dtor.ll (revision ce3485a0cd12b45c725f008a7836e71a1d72df49)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2; RUN: opt < %s -S -passes=globalopt | FileCheck %s
3
4declare dso_local i32 @atexit(ptr)
5
6define dso_local void @empty_atexit_handler() {
7; CHECK-LABEL: define dso_local void @empty_atexit_handler() local_unnamed_addr {
8; CHECK-NEXT:    ret void
9;
10  ret void
11}
12
13; Check that `atexit` is removed if the handler is empty.
14; Check that a removed `atexit` call returns `0` which is the value that denotes success.
15define dso_local noundef i32 @register_atexit_handler() {
16; CHECK-LABEL: define dso_local noundef i32 @register_atexit_handler() local_unnamed_addr {
17; CHECK-NEXT:    ret i32 0
18;
19  %1 = call i32 @atexit(ptr @empty_atexit_handler)
20  ret i32 %1
21}
22
23declare dso_local void @declared_atexit_handler()
24
25; Check that an atexit handler with only a declaration is not removed.
26define dso_local noundef i32 @register_declared_atexit_handler() {
27; CHECK-LABEL: define dso_local noundef i32 @register_declared_atexit_handler() local_unnamed_addr {
28; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @atexit(ptr @declared_atexit_handler)
29; CHECK-NEXT:    ret i32 [[TMP1]]
30;
31  %1 = call i32 @atexit(ptr @declared_atexit_handler)
32  ret i32 %1
33}
34
35declare dso_local void @external_exit_func()
36
37define dso_local void @nonempty_atexit_handler() {
38; CHECK-LABEL: define dso_local void @nonempty_atexit_handler() {
39; CHECK-NEXT:    call void @external_exit_func()
40; CHECK-NEXT:    ret void
41;
42  call void @external_exit_func()
43  ret void
44}
45
46; Check that an atexit handler that consists of any instructions other than `ret` is considered nonempty and not removed.
47define dso_local noundef i32 @register_nonempty_atexit_handler() {
48; CHECK-LABEL: define dso_local noundef i32 @register_nonempty_atexit_handler() local_unnamed_addr {
49; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @atexit(ptr @nonempty_atexit_handler)
50; CHECK-NEXT:    ret i32 [[TMP1]]
51;
52  %1 = call i32 @atexit(ptr @nonempty_atexit_handler)
53  ret i32 %1
54}
55