diff options
author | Anders Carlsson <andersca@mac.com> | 2009-12-03 03:06:55 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-12-03 03:06:55 +0000 |
commit | 5f91fd64b64875c066768cec80cfb5173e91cb42 (patch) | |
tree | dac8505dec80d409d1a66c1f1d17776aaa895183 | |
parent | 80bc5d5d0462d5aac628f4f5757cf3cb8582646f (diff) | |
download | bcm5719-llvm-5f91fd64b64875c066768cec80cfb5173e91cb42.tar.gz bcm5719-llvm-5f91fd64b64875c066768cec80cfb5173e91cb42.zip |
Add CodeGenModule::ComputeThunkAdjustment, which Eli wrote.
llvm-svn: 90401
-rw-r--r-- | clang/lib/CodeGen/CGClass.cpp | 36 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 7 |
2 files changed, 42 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index b3c2b986d19..fd2afe70e00 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -112,6 +112,42 @@ static llvm::Value *GetCXXBaseClassOffset(CodeGenFunction &CGF, return NonVirtualOffset; } +// FIXME: This probably belongs in CGVtable, but it relies on +// the static function ComputeNonVirtualBaseClassOffset, so we should make that +// a CodeGenModule member function as well. +ThunkAdjustment +CodeGenModule::ComputeThunkAdjustment(const CXXRecordDecl *ClassDecl, + const CXXRecordDecl *BaseClassDecl) { + CXXBasePaths Paths(/*FindAmbiguities=*/false, + /*RecordPaths=*/true, /*DetectVirtual=*/false); + if (!const_cast<CXXRecordDecl *>(ClassDecl)-> + isDerivedFrom(const_cast<CXXRecordDecl *>(BaseClassDecl), Paths)) { + assert(false && "Class must be derived from the passed in base class!"); + return ThunkAdjustment(); + } + + unsigned Start = 0; + uint64_t VirtualOffset = 0; + + const CXXBasePath &Path = Paths.front(); + const CXXRecordDecl *VBase = 0; + for (unsigned i = 0, e = Path.size(); i != e; ++i) { + const CXXBasePathElement& Element = Path[i]; + if (Element.Base->isVirtual()) { + Start = i+1; + QualType VBaseType = Element.Base->getType(); + VBase = cast<CXXRecordDecl>(VBaseType->getAs<RecordType>()->getDecl()); + } + } + if (VBase) + VirtualOffset = + getVtableInfo().getVirtualBaseOffsetIndex(ClassDecl, BaseClassDecl); + + uint64_t Offset = + ComputeNonVirtualBaseClassOffset(getContext(), Paths, Start); + return ThunkAdjustment(Offset, VirtualOffset); +} + llvm::Value * CodeGenFunction::GetAddressOfBaseClass(llvm::Value *Value, const CXXRecordDecl *ClassDecl, diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index e5bd3e2d48b..97465709176 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -232,7 +232,7 @@ public: /// GenerateRTTINonClass - Generate the rtti information for the given /// non-class type. llvm::Constant *GenerateRTTI(QualType Ty); - + /// BuildThunk - Build a thunk for the given method. llvm::Constant *BuildThunk(const CXXMethodDecl *MD, bool Extern, const ThunkAdjustment &ThisAdjustment); @@ -252,6 +252,11 @@ public: llvm::Constant *GetCXXBaseClassOffset(const CXXRecordDecl *ClassDecl, const CXXRecordDecl *BaseClassDecl); + /// ComputeThunkAdjustment - Returns the two parts required to compute the + /// offset for an object. + ThunkAdjustment ComputeThunkAdjustment(const CXXRecordDecl *ClassDecl, + const CXXRecordDecl *BaseClassDecl); + /// GetStringForStringLiteral - Return the appropriate bytes for a string /// literal, properly padded to match the literal type. If only the address of /// a constant is needed consider using GetAddrOfConstantStringLiteral. |