@@ -268,9 +268,9 @@ void CodeGenFunction::EmitAnyExprToMem(const Expr *E,
268
268
llvm_unreachable (" bad evaluation kind" );
269
269
}
270
270
271
- static void
272
- pushTemporaryCleanup (CodeGenFunction &CGF, const MaterializeTemporaryExpr *M ,
273
- const Expr *E, Address ReferenceTemporary) {
271
+ void CodeGenFunction::pushTemporaryCleanup ( const MaterializeTemporaryExpr *M,
272
+ const Expr *E ,
273
+ Address ReferenceTemporary) {
274
274
// Objective-C++ ARC:
275
275
// If we are binding a reference to a temporary that has ownership, we
276
276
// need to perform retain/release operations on the temporary.
@@ -305,9 +305,9 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M,
305
305
CleanupKind CleanupKind;
306
306
if (Lifetime == Qualifiers::OCL_Strong) {
307
307
const ValueDecl *VD = M->getExtendingDecl ();
308
- bool Precise =
309
- VD && isa<VarDecl>(VD) && VD->hasAttr <ObjCPreciseLifetimeAttr>();
310
- CleanupKind = CGF. getARCCleanupKind ();
308
+ bool Precise = isa_and_nonnull<VarDecl>(VD) &&
309
+ VD->hasAttr <ObjCPreciseLifetimeAttr>();
310
+ CleanupKind = getARCCleanupKind ();
311
311
Destroy = Precise ? &CodeGenFunction::destroyARCStrongPrecise
312
312
: &CodeGenFunction::destroyARCStrongImprecise;
313
313
} else {
@@ -317,13 +317,12 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M,
317
317
Destroy = &CodeGenFunction::destroyARCWeak;
318
318
}
319
319
if (Duration == SD_FullExpression)
320
- CGF.pushDestroy (CleanupKind, ReferenceTemporary,
321
- M->getType (), *Destroy,
322
- CleanupKind & EHCleanup);
320
+ pushDestroy (CleanupKind, ReferenceTemporary, M->getType (), *Destroy,
321
+ CleanupKind & EHCleanup);
323
322
else
324
- CGF. pushLifetimeExtendedDestroy (CleanupKind, ReferenceTemporary,
325
- M->getType (),
326
- *Destroy, CleanupKind & EHCleanup);
323
+ pushLifetimeExtendedDestroy (CleanupKind, ReferenceTemporary,
324
+ M->getType (), *Destroy ,
325
+ CleanupKind & EHCleanup);
327
326
return ;
328
327
329
328
case SD_Dynamic:
@@ -352,32 +351,31 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M,
352
351
llvm::FunctionCallee CleanupFn;
353
352
llvm::Constant *CleanupArg;
354
353
if (E->getType ()->isArrayType ()) {
355
- CleanupFn = CodeGenFunction (CGF. CGM ).generateDestroyHelper (
356
- ReferenceTemporary, E->getType (),
357
- CodeGenFunction::destroyCXXObject, CGF. getLangOpts ().Exceptions ,
354
+ CleanupFn = CodeGenFunction (CGM).generateDestroyHelper (
355
+ ReferenceTemporary, E->getType (), CodeGenFunction::destroyCXXObject,
356
+ getLangOpts ().Exceptions ,
358
357
dyn_cast_or_null<VarDecl>(M->getExtendingDecl ()));
359
- CleanupArg = llvm::Constant::getNullValue (CGF. Int8PtrTy );
358
+ CleanupArg = llvm::Constant::getNullValue (Int8PtrTy);
360
359
} else {
361
- CleanupFn = CGF. CGM .getAddrAndTypeOfCXXStructor (
360
+ CleanupFn = CGM.getAddrAndTypeOfCXXStructor (
362
361
GlobalDecl (ReferenceTemporaryDtor, Dtor_Complete));
363
- CleanupArg = cast<llvm::Constant>(ReferenceTemporary.emitRawPointer (CGF));
362
+ CleanupArg =
363
+ cast<llvm::Constant>(ReferenceTemporary.emitRawPointer (*this ));
364
364
}
365
- CGF. CGM .getCXXABI ().registerGlobalDtor (
366
- CGF , *cast<VarDecl>(M->getExtendingDecl ()), CleanupFn, CleanupArg);
365
+ CGM.getCXXABI ().registerGlobalDtor (
366
+ * this , *cast<VarDecl>(M->getExtendingDecl ()), CleanupFn, CleanupArg);
367
367
break ;
368
368
}
369
369
370
370
case SD_FullExpression:
371
- CGF.pushDestroy (NormalAndEHCleanup, ReferenceTemporary, E->getType (),
372
- CodeGenFunction::destroyCXXObject,
373
- CGF.getLangOpts ().Exceptions );
371
+ pushDestroy (NormalAndEHCleanup, ReferenceTemporary, E->getType (),
372
+ CodeGenFunction::destroyCXXObject, getLangOpts ().Exceptions );
374
373
break ;
375
374
376
375
case SD_Automatic:
377
- CGF.pushLifetimeExtendedDestroy (NormalAndEHCleanup,
378
- ReferenceTemporary, E->getType (),
379
- CodeGenFunction::destroyCXXObject,
380
- CGF.getLangOpts ().Exceptions );
376
+ pushLifetimeExtendedDestroy (NormalAndEHCleanup, ReferenceTemporary,
377
+ E->getType (), CodeGenFunction::destroyCXXObject,
378
+ getLangOpts ().Exceptions );
381
379
break ;
382
380
383
381
case SD_Dynamic:
@@ -484,7 +482,7 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
484
482
}
485
483
}
486
484
487
- pushTemporaryCleanup (* this , M, E, Object);
485
+ pushTemporaryCleanup (M, E, Object);
488
486
return RefTempDst;
489
487
}
490
488
@@ -573,7 +571,13 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
573
571
}
574
572
EmitAnyExprToMem (E, Object, Qualifiers (), /* IsInit*/ true );
575
573
}
576
- pushTemporaryCleanup (*this , M, E, Object);
574
+
575
+ // If this temporary extended by for-range variable, delay to emitting
576
+ // cleanup.
577
+ if (!CurLexicalScope->isExtendedByForRangeVar (M))
578
+ CurLexicalScope->addForRangeInitTemp (M, Object);
579
+ else
580
+ pushTemporaryCleanup (M, E, Object);
577
581
578
582
// Perform derived-to-base casts and/or field accesses, to get from the
579
583
// temporary object we created (and, potentially, for which we extended
0 commit comments