Use the existing API for base offset. Use suitable llvm type
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 29 Jul 2009 15:54:56 +0000 (15:54 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 29 Jul 2009 15:54:56 +0000 (15:54 +0000)
for offset ir-gen.

llvm-svn: 77458

clang/lib/CodeGen/CGCXX.cpp

index 0b22eb4..050323a 100644 (file)
@@ -167,26 +167,10 @@ llvm::Value *CodeGenFunction::AddressCXXOfBaseClass(llvm::Value *BaseValue,
   const ASTRecordLayout &Layout = 
   getContext().getASTRecordLayout(ClassDecl);
   llvm::Type *I8Ptr = VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty);
-  unsigned Idx = 0;
-  bool DerivedToBaseConversion = false;
-  for (CXXRecordDecl::base_class_const_iterator i = 
-         ClassDecl->bases_begin(),
-         e = ClassDecl->bases_end(); i != e; ++i, ++Idx) {
-    if (!i->isVirtual()) {
-        const CXXRecordDecl *Base =
-        cast<CXXRecordDecl>(i->getType()->getAsRecordType()->getDecl());
-      if (Base == BaseClassDecl) {
-        DerivedToBaseConversion = true;
-        break;
-      }
-    }
-  }
-  if (!DerivedToBaseConversion) {
-    assert(false && "FIXME - Only derived to imm. base convesion is supported");
-    return BaseValue;
-  }
-  uint64_t Offset = Layout.getFieldOffset(Idx) / 8;
-  llvm::Value *OffsetVal = llvm::ConstantInt::get(llvm::Type::Int32Ty, Offset);
+  uint64_t Offset = Layout.getBaseClassOffset(BaseClassDecl) / 8;
+  llvm::Value *OffsetVal = 
+    llvm::ConstantInt::get(
+                  CGM.getTypes().ConvertType(CGM.getContext().LongTy), Offset);
   BaseValue = Builder.CreateBitCast(BaseValue, I8Ptr);
   BaseValue = Builder.CreateGEP(BaseValue, OffsetVal, "add.ptr");
   QualType BTy =