@@ -2146,8 +2146,22 @@ static Address createReferenceTemporary(CIRGenFunction &CGF,
21462146 (Ty->isArrayType () || Ty->isRecordType ()) &&
21472147 CGF.CGM .isTypeConstant (Ty, /* ExcludeCtor=*/ true , /* ExcludeDtor=*/ false ))
21482148 assert (0 && " NYI" );
2149+
2150+ // The temporary memory should be created in the same scope as the extending
2151+ // declaration of the temporary materialization expression.
2152+ mlir::cir::AllocaOp extDeclAlloca;
2153+ if (const clang::ValueDecl *extDecl = M->getExtendingDecl ()) {
2154+ auto extDeclAddrIter = CGF.LocalDeclMap .find (extDecl);
2155+ if (extDeclAddrIter != CGF.LocalDeclMap .end ()) {
2156+ extDeclAlloca = dyn_cast_if_present<mlir::cir::AllocaOp>(
2157+ extDeclAddrIter->second .getDefiningOp ());
2158+ }
2159+ }
2160+ mlir::OpBuilder::InsertPoint ip;
2161+ if (extDeclAlloca)
2162+ ip = {extDeclAlloca->getBlock (), extDeclAlloca->getIterator ()};
21492163 return CGF.CreateMemTemp (Ty, CGF.getLoc (M->getSourceRange ()),
2150- CGF.getCounterRefTmpAsString (), Alloca);
2164+ CGF.getCounterRefTmpAsString (), Alloca, ip );
21512165 }
21522166 case SD_Thread:
21532167 case SD_Static:
@@ -2245,7 +2259,7 @@ LValue CIRGenFunction::buildMaterializeTemporaryExpr(
22452259 } else {
22462260 switch (M->getStorageDuration ()) {
22472261 case SD_Automatic:
2248- assert (0 && " NYI " );
2262+ assert (! MissingFeatures::shouldEmitLifetimeMarkers () );
22492263 break ;
22502264
22512265 case SD_FullExpression: {
@@ -2932,18 +2946,20 @@ void CIRGenFunction::buildUnreachable(SourceLocation Loc) {
29322946// ===----------------------------------------------------------------------===//
29332947
29342948Address CIRGenFunction::CreateMemTemp (QualType Ty, mlir::Location Loc,
2935- const Twine &Name, Address *Alloca) {
2949+ const Twine &Name, Address *Alloca,
2950+ mlir::OpBuilder::InsertPoint ip) {
29362951 // FIXME: Should we prefer the preferred type alignment here?
29372952 return CreateMemTemp (Ty, getContext ().getTypeAlignInChars (Ty), Loc, Name,
2938- Alloca);
2953+ Alloca, ip );
29392954}
29402955
29412956Address CIRGenFunction::CreateMemTemp (QualType Ty, CharUnits Align,
29422957 mlir::Location Loc, const Twine &Name,
2943- Address *Alloca) {
2958+ Address *Alloca,
2959+ mlir::OpBuilder::InsertPoint ip) {
29442960 Address Result =
29452961 CreateTempAlloca (getTypes ().convertTypeForMem (Ty), Align, Loc, Name,
2946- /* ArraySize=*/ nullptr , Alloca);
2962+ /* ArraySize=*/ nullptr , Alloca, ip );
29472963 if (Ty->isConstantMatrixType ()) {
29482964 assert (0 && " NYI" );
29492965 }
0 commit comments