[clang] [CIR] Add Minimal Destructor Definition Support (PR #144719)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 18 11:29:23 PDT 2025


================
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir -mno-constructor-aliases %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -mno-constructor-aliases -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -mno-constructor-aliases -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
+
+void some_function() noexcept;
+
+struct out_of_line_destructor {
+    int prevent_tail_padding_reuse;
+    ~out_of_line_destructor();
+};
+
+out_of_line_destructor::~out_of_line_destructor() {
+    some_function();
+}
+
+// CIR: !rec_out_of_line_destructor = !cir.record<struct "out_of_line_destructor" {!s32i}>
+
+// CIR: cir.func @_ZN22out_of_line_destructorD2Ev(%{{.+}}: !cir.ptr<!rec_out_of_line_destructor>
+// CIR:   cir.call @_Z13some_functionv() : () -> () 
+// CIR:   cir.return 
+
+// LLVM: define void @_ZN22out_of_line_destructorD2Ev(ptr %{{.+}})
+// LLVM:   call void @_Z13some_functionv()
+// LLVM:   ret void
+
+// OGCG: define dso_local void @_ZN22out_of_line_destructorD2Ev(ptr {{.*}}%{{.+}})
+// OGCG:   call void @_Z13some_functionv()
+// OGCG:   ret void
+
+// CIR: cir.func @_ZN22out_of_line_destructorD1Ev(%{{.+}}: !cir.ptr<!rec_out_of_line_destructor>
+// CIR:  cir.call @_Z13some_functionv() : () -> ()
+// CIR:  cir.return
+
+// LLVM: define void @_ZN22out_of_line_destructorD1Ev(ptr %{{.+}})
+// LLVM:   call void @_Z13some_functionv()
+// LLVM:   ret void
+
+// OGCG: define dso_local void @_ZN22out_of_line_destructorD1Ev(ptr {{.*}}%{{.+}})
+// OGCG:   call void @_ZN22out_of_line_destructorD2Ev
+// OGCG:   ret void
+
+struct inline_destructor {
----------------
andykaylor wrote:

We're not emitting code for this case, right? You should probably delete it until we do.

https://github.com/llvm/llvm-project/pull/144719


More information about the cfe-commits mailing list