[llvm] [llvm][GlobalOpt] Remove empty atexit destructors/handlers (PR #88836)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 25 21:44:27 PDT 2024
================
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt < %s -S -passes=globalopt | FileCheck %s
+
+declare dso_local i32 @atexit(ptr)
+
+define dso_local void @atexit_handler() {
+; CHECK-LABEL: define dso_local void @atexit_handler() local_unnamed_addr {
+; CHECK-NEXT: ret void
+;
+ ret void
+}
+
+; Check that `atexit` is removed if the handler is empty.
+; Check that a removed `atexit` call returns `0` which is the value that denotes success.
+define dso_local noundef i32 @register_atexit_handler() {
+; CHECK-LABEL: define dso_local noundef i32 @register_atexit_handler() local_unnamed_addr {
+; CHECK-NEXT: [[TMP1:%.*]] = alloca i32, align 4
+; CHECK-NEXT: store i32 0, ptr [[TMP1]], align 4
+; CHECK-NEXT: ret i32 0
+;
+ %1 = alloca i32, align 4
+ store i32 0, ptr %1, align 4
+ %2 = call i32 @atexit(ptr @"atexit_handler")
+ ret i32 %2
----------------
nikic wrote:
Could you please add another call to atexit with a non-empty function as a negative test (i.e., to show that it will not be removed)?
https://github.com/llvm/llvm-project/pull/88836
More information about the llvm-commits
mailing list