diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-11-27 04:46:20 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-11-27 04:46:20 +0000 |
commit | c6fdb7765fc872eea8dfc5fb0ee984c0fbac1068 (patch) | |
tree | 4dad1bd56ecd7837c1bbdf0b039f9165b8cc526e /lib/CodeGen/CGExprAgg.cpp | |
parent | d888962cff03b543fbe9ac6051ec6addf5b993b4 (diff) |
Add case for CK_DerivedToBaseMemberPointer cast kind to
AggExprEmitter::VisitCastExpr.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89988 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprAgg.cpp')
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 0c8f1e6934..9a2aae7f8b 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -223,6 +223,7 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { break; } + case CastExpr::CK_DerivedToBaseMemberPointer: case CastExpr::CK_BaseToDerivedMemberPointer: { QualType SrcType = E->getSubExpr()->getType(); @@ -242,16 +243,22 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { llvm::Value *DstAdj = Builder.CreateStructGEP(DestPtr, 1, "dst.adj"); // Now See if we need to update the adjustment. - const CXXRecordDecl *SrcDecl = + const CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(SrcType->getAs<MemberPointerType>()-> getClass()->getAs<RecordType>()->getDecl()); - const CXXRecordDecl *DstDecl = + const CXXRecordDecl *DerivedDecl = cast<CXXRecordDecl>(E->getType()->getAs<MemberPointerType>()-> getClass()->getAs<RecordType>()->getDecl()); - - llvm::Constant *Adj = CGF.CGM.GetCXXBaseClassOffset(DstDecl, SrcDecl); - if (Adj) - SrcAdj = Builder.CreateAdd(SrcAdj, Adj, "adj"); + if (E->getCastKind() == CastExpr::CK_DerivedToBaseMemberPointer) + std::swap(DerivedDecl, BaseDecl); + + llvm::Constant *Adj = CGF.CGM.GetCXXBaseClassOffset(DerivedDecl, BaseDecl); + if (Adj) { + if (E->getCastKind() == CastExpr::CK_DerivedToBaseMemberPointer) + SrcAdj = Builder.CreateSub(SrcAdj, Adj, "adj"); + else + SrcAdj = Builder.CreateAdd(SrcAdj, Adj, "adj"); + } Builder.CreateStore(SrcAdj, DstAdj, VolatileDest); break; |