]> granicus.if.org Git - clang/commitdiff
Add CodeGenModule::ComputeThunkAdjustment, which Eli wrote.
authorAnders Carlsson <andersca@mac.com>
Thu, 3 Dec 2009 03:06:55 +0000 (03:06 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 3 Dec 2009 03:06:55 +0000 (03:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90401 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGClass.cpp
lib/CodeGen/CodeGenModule.h

index b3c2b986d1903c811ddec72ad6079f2e41c77210..fd2afe70e00ed6e42a567af894a7fd873d710fdd 100644 (file)
@@ -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,
index e5bd3e2d48b39e5ef7a52a47cdb183f3dde0a388..974657091765547350db8029b40f121032a5b392 100644 (file)
@@ -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.