@@ -361,8 +361,36 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) {
361
361
Builder.CreateStore (Loc, Addr);
362
362
continue ;
363
363
} else {
364
- if (BDRE->getCopyConstructorExpr ())
365
- E = BDRE->getCopyConstructorExpr ();
364
+ if (BDRE->getCopyConstructorExpr ()) {
365
+ E = BDRE->getCopyConstructorExpr ();
366
+ // Code to destruct copy-constructed descriptor element for
367
+ // copied-in class object.
368
+ // TODO: Refactor this into common code with mostly similar
369
+ // CodeGenFunction::EmitLocalBlockVarDecl
370
+ QualType DtorTy = E->getType ();
371
+ if (const RecordType *RT = DtorTy->getAs <RecordType>())
372
+ if (CXXRecordDecl *ClassDecl =
373
+ dyn_cast<CXXRecordDecl>(RT->getDecl ())) {
374
+ if (!ClassDecl->hasTrivialDestructor ()) {
375
+ const CXXDestructorDecl *D =
376
+ ClassDecl->getDestructor (getContext ());
377
+ assert (D && " BuildBlockLiteralTmp - destructor is nul" );
378
+ {
379
+ // Normal destruction.
380
+ DelayedCleanupBlock Scope (*this );
381
+ EmitCXXDestructorCall (D, Dtor_Complete,
382
+ /* ForVirtualBase=*/ false , Addr);
383
+ // Make sure to jump to the exit block.
384
+ EmitBranch (Scope.getCleanupExitBlock ());
385
+ }
386
+ if (Exceptions) {
387
+ EHCleanupBlock Cleanup (*this );
388
+ EmitCXXDestructorCall (D, Dtor_Complete,
389
+ /* ForVirtualBase=*/ false , Addr);
390
+ }
391
+ }
392
+ }
393
+ }
366
394
else {
367
395
E = new (getContext ()) DeclRefExpr (const_cast <ValueDecl*>(VD),
368
396
VD->getType ().getNonReferenceType (),
0 commit comments