@@ -2146,8 +2146,22 @@ static Address createReferenceTemporary(CIRGenFunction &CGF,
2146
2146
(Ty->isArrayType () || Ty->isRecordType ()) &&
2147
2147
CGF.CGM .isTypeConstant (Ty, /* ExcludeCtor=*/ true , /* ExcludeDtor=*/ false ))
2148
2148
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 ()};
2149
2163
return CGF.CreateMemTemp (Ty, CGF.getLoc (M->getSourceRange ()),
2150
- CGF.getCounterRefTmpAsString (), Alloca);
2164
+ CGF.getCounterRefTmpAsString (), Alloca, ip );
2151
2165
}
2152
2166
case SD_Thread:
2153
2167
case SD_Static:
@@ -2245,7 +2259,7 @@ LValue CIRGenFunction::buildMaterializeTemporaryExpr(
2245
2259
} else {
2246
2260
switch (M->getStorageDuration ()) {
2247
2261
case SD_Automatic:
2248
- assert (0 && " NYI " );
2262
+ assert (! MissingFeatures::shouldEmitLifetimeMarkers () );
2249
2263
break ;
2250
2264
2251
2265
case SD_FullExpression: {
@@ -2932,18 +2946,20 @@ void CIRGenFunction::buildUnreachable(SourceLocation Loc) {
2932
2946
// ===----------------------------------------------------------------------===//
2933
2947
2934
2948
Address CIRGenFunction::CreateMemTemp (QualType Ty, mlir::Location Loc,
2935
- const Twine &Name, Address *Alloca) {
2949
+ const Twine &Name, Address *Alloca,
2950
+ mlir::OpBuilder::InsertPoint ip) {
2936
2951
// FIXME: Should we prefer the preferred type alignment here?
2937
2952
return CreateMemTemp (Ty, getContext ().getTypeAlignInChars (Ty), Loc, Name,
2938
- Alloca);
2953
+ Alloca, ip );
2939
2954
}
2940
2955
2941
2956
Address CIRGenFunction::CreateMemTemp (QualType Ty, CharUnits Align,
2942
2957
mlir::Location Loc, const Twine &Name,
2943
- Address *Alloca) {
2958
+ Address *Alloca,
2959
+ mlir::OpBuilder::InsertPoint ip) {
2944
2960
Address Result =
2945
2961
CreateTempAlloca (getTypes ().convertTypeForMem (Ty), Align, Loc, Name,
2946
- /* ArraySize=*/ nullptr , Alloca);
2962
+ /* ArraySize=*/ nullptr , Alloca, ip );
2947
2963
if (Ty->isConstantMatrixType ()) {
2948
2964
assert (0 && " NYI" );
2949
2965
}
0 commit comments