File tree Expand file tree Collapse file tree 3 files changed +27
-9
lines changed Expand file tree Collapse file tree 3 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -574,17 +574,17 @@ template <class Emitter> class LocalScope : public VariableScope<Emitter> {
574
574
// Emit destructor calls for local variables of record
575
575
// type with a destructor.
576
576
for (Scope::Local &Local : llvm::reverse (this ->Ctx ->Descriptors [*Idx])) {
577
- if (!Local.Desc ->isPrimitive () && !Local.Desc ->isPrimitiveArray ()) {
578
- if (!this ->Ctx ->emitGetPtrLocal (Local.Offset , E))
579
- return false ;
577
+ if (Local.Desc ->hasTrivialDtor ())
578
+ continue ;
579
+ if (!this ->Ctx ->emitGetPtrLocal (Local.Offset , E))
580
+ return false ;
580
581
581
- if (!this ->Ctx ->emitDestruction (Local.Desc , Local.Desc ->getLoc ()))
582
- return false ;
582
+ if (!this ->Ctx ->emitDestruction (Local.Desc , Local.Desc ->getLoc ()))
583
+ return false ;
583
584
584
- if (!this ->Ctx ->emitPopPtr (E))
585
- return false ;
586
- removeIfStoredOpaqueValue (Local);
587
- }
585
+ if (!this ->Ctx ->emitPopPtr (E))
586
+ return false ;
587
+ removeIfStoredOpaqueValue (Local);
588
588
}
589
589
return true ;
590
590
}
Original file line number Diff line number Diff line change @@ -502,6 +502,21 @@ SourceInfo Descriptor::getLoc() const {
502
502
llvm_unreachable (" Invalid descriptor type" );
503
503
}
504
504
505
+ bool Descriptor::hasTrivialDtor () const {
506
+ if (isPrimitive () || isPrimitiveArray () || isDummy ())
507
+ return true ;
508
+
509
+ if (isRecord ()) {
510
+ assert (ElemRecord);
511
+ const CXXDestructorDecl *Dtor = ElemRecord->getDestructor ();
512
+ return !Dtor || Dtor->isTrivial ();
513
+ }
514
+
515
+ // Composite arrays.
516
+ assert (ElemDesc);
517
+ return ElemDesc->hasTrivialDtor ();
518
+ }
519
+
505
520
bool Descriptor::isUnion () const { return isRecord () && ElemRecord->isUnion (); }
506
521
507
522
InitMap::InitMap (unsigned N)
Original file line number Diff line number Diff line change @@ -281,6 +281,9 @@ struct Descriptor final {
281
281
// / Checks if this is a dummy descriptor.
282
282
bool isDummy () const { return IsDummy; }
283
283
284
+ // / Whether variables of this descriptor need their destructor called or not.
285
+ bool hasTrivialDtor () const ;
286
+
284
287
void dump () const ;
285
288
void dump (llvm::raw_ostream &OS) const ;
286
289
void dumpFull (unsigned Offset = 0 , unsigned Indent = 0 ) const ;
You can’t perform that action at this time.
0 commit comments