[clang] [CIR] Implement global array dtor support (PR #169070)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 21 09:58:19 PST 2025
================
@@ -693,6 +696,101 @@ void LoweringPreparePass::lowerUnaryOp(cir::UnaryOp op) {
op.erase();
}
+cir::FuncOp LoweringPreparePass::getOrCreateDtorFunc(CIRBaseBuilderTy &builder,
+ cir::GlobalOp op,
+ mlir::Region &dtorRegion,
+ cir::CallOp &dtorCall) {
+ assert(!cir::MissingFeatures::astVarDeclInterface());
+ assert(!cir::MissingFeatures::opGlobalThreadLocal());
+
+ cir::VoidType voidTy = builder.getVoidTy();
+ auto voidPtrTy = cir::PointerType::get(voidTy);
+
+ // Look for operations in dtorBlock
+ mlir::Block &dtorBlock = dtorRegion.front();
+
+ // The first operation should be a get_global to retrieve the address
+ // of the global variable we're destroying.
+ auto opIt = dtorBlock.getOperations().begin();
+ cir::GetGlobalOp ggop = mlir::cast<cir::GetGlobalOp>(*opIt);
+
+ // The simple case is just a call to a destructor, like this:
+ //
+ // %0 = cir.get_global %globalS : !cir.ptr<!rec_S>
----------------
erichkeane wrote:
Its a little weird that this global is required... could we make a helper for 'createDestroy' (or whatever it is?) to take the 'location' of the get and synthesize it? It just seems odd we have a 'get_global' <this>.
Alternatively, can we assert that the global IS the current variable as a sanity assert?
https://github.com/llvm/llvm-project/pull/169070
More information about the cfe-commits
mailing list