[clang] [CIR] Handle expression with cleanups (PR #151600)

Henrich Lauko via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 1 07:52:50 PDT 2025


================
@@ -1096,6 +1096,154 @@ void CIRGenFunction::emitAnyExprToMem(const Expr *e, Address location,
   llvm_unreachable("bad evaluation kind");
 }
 
+static Address createReferenceTemporary(CIRGenFunction &cgf,
+                                        const MaterializeTemporaryExpr *m,
+                                        const Expr *inner) {
+  // TODO(cir): cgf.getTargetHooks();
+  switch (m->getStorageDuration()) {
+  case SD_FullExpression:
+  case SD_Automatic: {
+    QualType ty = inner->getType();
+
+    assert(!cir::MissingFeatures::mergeAllConstants());
+
+    // The temporary memory should be created in the same scope as the extending
+    // declaration of the temporary materialization expression.
+    cir::AllocaOp extDeclAlloca;
+    if (const clang::ValueDecl *extDecl = m->getExtendingDecl()) {
+      auto extDeclAddrIter = cgf.localDeclMap.find(extDecl);
+      if (extDeclAddrIter != cgf.localDeclMap.end()) {
+        extDeclAlloca = mlir::dyn_cast_if_present<cir::AllocaOp>(
+            extDeclAddrIter->second.getDefiningOp());
----------------
xlauko wrote:

```suggestion
        extDeclAlloca = extDeclAddrIter->second.getDefiningOp<cir::AllocaOp>();
```

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


More information about the cfe-commits mailing list