[cfe-commits] r77339 - in /cfe/trunk/lib/CodeGen: CGCXX.cpp CodeGenFunction.h

Fariborz Jahanian fjahanian at apple.com
Tue Jul 28 11:09:28 PDT 2009


Author: fjahanian
Date: Tue Jul 28 13:09:28 2009
New Revision: 77339

URL: http://llvm.org/viewvc/llvm-project?rev=77339&view=rev
Log:
Some code cleanup.


Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=77339&r1=77338&r2=77339&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Jul 28 13:09:28 2009
@@ -156,8 +156,8 @@
 }
 
 llvm::Value *CodeGenFunction::AddressCXXOfBaseClass(llvm::Value *BaseValue,
-                                                CXXRecordDecl *ClassDecl, 
-                                                CXXRecordDecl *BaseClassDecl) {
+                                          const CXXRecordDecl *ClassDecl, 
+                                          const CXXRecordDecl *BaseClassDecl) {
   if (ClassDecl == BaseClassDecl)
     return BaseValue;
   
@@ -184,7 +184,7 @@
   BaseValue = Builder.CreateGEP(BaseValue, OffsetVal, "add.ptr");
   QualType BTy = 
     getContext().getCanonicalType(
-                                  getContext().getTypeDeclType(BaseClassDecl));
+      getContext().getTypeDeclType(const_cast<CXXRecordDecl*>(BaseClassDecl)));
   const llvm::Type *BasePtr = ConvertType(BTy);
   BasePtr = VMContext.getPointerTypeUnqual(BasePtr);
   BaseValue = Builder.CreateBitCast(BaseValue, BasePtr);
@@ -458,33 +458,18 @@
   const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(CD->getDeclContext());
   assert(ClassDecl->vbases_begin() == ClassDecl->vbases_end()
          && "FIXME. virtual base initialization unsupported");
-  const ASTRecordLayout &Layout = getContext().getASTRecordLayout(ClassDecl);
-  llvm::Type *I8Ptr = VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty);
-  unsigned FieldNo = 0;
+  
   for (CXXConstructorDecl::init_const_iterator B = CD->init_begin(),
        E = CD->init_end();
        B != E; ++B) {
     CXXBaseOrMemberInitializer *Member = (*B);
     if (Member->isBaseInitializer()) {
-      uint64_t Offset = Layout.getFieldOffset(FieldNo++) / 8;
-      assert(Member->getConstructor() && 
-             "EmitCtorPrologue - no constructor to initialize base class");
       llvm::Value *LoadOfThis = LoadCXXThis();
-      llvm::LLVMContext &VMContext = getLLVMContext();
-      llvm::Value *V;
-      if (Offset > 0) {
-        llvm::Value *OffsetVal = llvm::ConstantInt::get(llvm::Type::Int32Ty,
-                                                        Offset);
-        V = Builder.CreateBitCast(LoadOfThis, I8Ptr);
-        V = Builder.CreateGEP(V, OffsetVal, "add.ptr");
-      }
-      else
-        V = Builder.CreateBitCast(LoadOfThis, I8Ptr);
-
-      const llvm::Type *BasePtr = 
-        ConvertType(QualType(Member->getBaseClass(), 0));
-      BasePtr = VMContext.getPointerTypeUnqual(BasePtr);
-      V = Builder.CreateBitCast(V, BasePtr);
+      Type *BaseType = Member->getBaseClass();
+      CXXRecordDecl *BaseClassDecl = 
+        cast<CXXRecordDecl>(BaseType->getAsRecordType()->getDecl());
+      llvm::Value *V = AddressCXXOfBaseClass(LoadOfThis, ClassDecl, 
+                                             BaseClassDecl);
       EmitCXXConstructorCall(Member->getConstructor(),
                              Ctor_Complete, V,
                              Member->const_arg_begin(), 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=77339&r1=77338&r2=77339&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Jul 28 13:09:28 2009
@@ -533,8 +533,8 @@
   // FIXME. This currently only does a derived to non-virtual base conversion. 
   // Other kinds of conversions will come later.
   llvm::Value *AddressCXXOfBaseClass(llvm::Value *ThisValue,
-                                     CXXRecordDecl *ClassDecl, 
-                                     CXXRecordDecl *BaseClassDecl);
+                                     const CXXRecordDecl *ClassDecl, 
+                                     const CXXRecordDecl *BaseClassDecl);
   
   void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, 
                               llvm::Value *This,





More information about the cfe-commits mailing list