[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


================
@@ -538,6 +538,104 @@ void CIRGenFunction::emitConstructorBody(FunctionArgList &args) {
   }
 }
 
+/// Emits the body of the current destructor.
+void CIRGenFunction::emitDestructorBody(FunctionArgList &args) {
+  const CXXDestructorDecl *dtor = cast<CXXDestructorDecl>(curGD.getDecl());
+  CXXDtorType dtorType = curGD.getDtorType();
+
+  // For an abstract class, non-base destructors are never used (and can't
+  // be emitted in general, because vbase dtors may not have been validated
+  // by Sema), but the Itanium ABI doesn't make them optional and Clang may
+  // in fact emit references to them from other compilations, so emit them
+  // as functions containing a trap instruction.
+  if (dtorType != Dtor_Base && dtor->getParent()->isAbstract()) {
+    SourceLocation loc =
+        dtor->hasBody() ? dtor->getBody()->getBeginLoc() : dtor->getLocation();
+    builder.create<cir::TrapOp>(getLoc(loc));
+    // The corresponding clang/CodeGen logic clears the insertion point here,
+    // but MLIR's builder requires a valid insertion point, so we create a dummy
+    // block (since the trap is a block terminator).
+    builder.createBlock(builder.getBlock()->getParent());
+    return;
+  }
+
+  Stmt *body = dtor->getBody();
+  if (body)
----------------
andykaylor wrote:

I don't think it's useful to put this assert inside an `if`.

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


More information about the cfe-commits mailing list