@@ -110,8 +110,8 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
110
110
if (!this ->visit (SubExpr))
111
111
return false ;
112
112
113
- unsigned DerivedOffset = collectBaseOffset ( getRecordTy (CE-> getType ()),
114
- getRecordTy (SubExpr ->getType ()));
113
+ unsigned DerivedOffset =
114
+ collectBaseOffset (CE ->getType (), SubExpr-> getType ( ));
115
115
116
116
return this ->emitGetPtrBasePop (DerivedOffset, CE);
117
117
}
@@ -120,8 +120,8 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
120
120
if (!this ->visit (SubExpr))
121
121
return false ;
122
122
123
- unsigned DerivedOffset = collectBaseOffset ( getRecordTy (SubExpr-> getType ()),
124
- getRecordTy (CE ->getType ()));
123
+ unsigned DerivedOffset =
124
+ collectBaseOffset (SubExpr ->getType (), CE-> getType ( ));
125
125
126
126
return this ->emitGetPtrDerivedPop (DerivedOffset, CE);
127
127
}
@@ -3529,35 +3529,17 @@ void ByteCodeExprGen<Emitter>::emitCleanup() {
3529
3529
3530
3530
template <class Emitter >
3531
3531
unsigned
3532
- ByteCodeExprGen<Emitter>::collectBaseOffset(const RecordType *BaseType,
3533
- const RecordType *DerivedType) {
3534
- assert (BaseType);
3535
- assert (DerivedType);
3536
- const auto *FinalDecl = cast<CXXRecordDecl>(BaseType->getDecl ());
3537
- const RecordDecl *CurDecl = DerivedType->getDecl ();
3538
- const Record *CurRecord = getRecord (CurDecl);
3539
- assert (CurDecl && FinalDecl);
3540
-
3541
- unsigned OffsetSum = 0 ;
3542
- for (;;) {
3543
- assert (CurRecord->getNumBases () > 0 );
3544
- // One level up
3545
- for (const Record::Base &B : CurRecord->bases ()) {
3546
- const auto *BaseDecl = cast<CXXRecordDecl>(B.Decl );
3547
-
3548
- if (BaseDecl == FinalDecl || BaseDecl->isDerivedFrom (FinalDecl)) {
3549
- OffsetSum += B.Offset ;
3550
- CurRecord = B.R ;
3551
- CurDecl = BaseDecl;
3552
- break ;
3553
- }
3554
- }
3555
- if (CurDecl == FinalDecl)
3556
- break ;
3557
- }
3532
+ ByteCodeExprGen<Emitter>::collectBaseOffset(const QualType BaseType,
3533
+ const QualType DerivedType) {
3534
+ const auto extractRecordDecl = [](QualType Ty) -> const CXXRecordDecl * {
3535
+ if (const auto *PT = dyn_cast<PointerType>(Ty))
3536
+ return PT->getPointeeType ()->getAsCXXRecordDecl ();
3537
+ return Ty->getAsCXXRecordDecl ();
3538
+ };
3539
+ const CXXRecordDecl *BaseDecl = extractRecordDecl (BaseType);
3540
+ const CXXRecordDecl *DerivedDecl = extractRecordDecl (DerivedType);
3558
3541
3559
- assert (OffsetSum > 0 );
3560
- return OffsetSum;
3542
+ return Ctx.collectBaseOffset (BaseDecl, DerivedDecl);
3561
3543
}
3562
3544
3563
3545
// / Emit casts from a PrimType to another PrimType.
0 commit comments