[cfe-commits] r77351 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp lib/CodeGen/CGExpr.cpp test/CodeGenCXX/constructor-init.cpp

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


Author: fjahanian
Date: Tue Jul 28 13:54:57 2009
New Revision: 77351

URL: http://llvm.org/viewvc/llvm-project?rev=77351&view=rev
Log:
More cleanup of data member access and then some.


Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGenCXX/constructor-init.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Jul 28 13:54:57 2009
@@ -168,16 +168,23 @@
   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)
-          break;
+      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);
   BaseValue = Builder.CreateBitCast(BaseValue, I8Ptr);

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Jul 28 13:54:57 2009
@@ -993,15 +993,14 @@
     if (PTy->getPointeeType()->isUnionType())
       isUnion = true;
     CVRQualifiers = PTy->getPointeeType().getCVRQualifiers();
-    if (CXXThisExpr *ThisExpr = dyn_cast<CXXThisExpr>(BaseExpr)) {
-      QualType ClassTy = ThisExpr->getType();
-      ClassTy = ClassTy->getPointeeType();
-      CXXRecordDecl *ClassDecl =
-        cast<CXXRecordDecl>(ClassTy->getAsRecordType()->getDecl());
+    QualType ClassTy = BaseExpr->getType();
+    ClassTy = ClassTy->getPointeeType();
+    if (CXXRecordDecl *ClassDecl =
+        dyn_cast<CXXRecordDecl>(ClassTy->getAsRecordType()->getDecl())) {
       FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
-      CXXRecordDecl *BaseClassDecl = 
-        cast<CXXRecordDecl>(Field->getDeclContext());
-      BaseValue = AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
+      if (CXXRecordDecl *BaseClassDecl = 
+          dyn_cast<CXXRecordDecl>(Field->getDeclContext()))
+        BaseValue = AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
     }
   } else if (isa<ObjCPropertyRefExpr>(BaseExpr) ||
              isa<ObjCKVCRefExpr>(BaseExpr)) {
@@ -1021,6 +1020,15 @@
     if (BaseExpr->getType()->isUnionType())
       isUnion = true;
     CVRQualifiers = BaseExpr->getType().getCVRQualifiers();
+    if (CXXRecordDecl *ClassDecl =
+          dyn_cast<CXXRecordDecl>(
+                        BaseExpr->getType()->getAsRecordType()->getDecl())) {
+        FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());
+        if (CXXRecordDecl *BaseClassDecl = 
+            dyn_cast<CXXRecordDecl>(Field->getDeclContext()))
+            BaseValue = 
+              AddressCXXOfBaseClass(BaseValue, ClassDecl, BaseClassDecl);
+    }
   }
 
   FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl());

Modified: cfe/trunk/test/CodeGenCXX/constructor-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/constructor-init.cpp?rev=77351&r1=77350&r2=77351&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/constructor-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/constructor-init.cpp Tue Jul 28 13:54:57 2009
@@ -38,6 +38,9 @@
 	      printf("iQ = %d\n", iQ);
 	      printf("iP = %d\n", iP);
               printf("iM = %d\n", iM);
+	      printf("iQ = %d\n", (*this).iQ);
+	      printf("iP = %d\n", ((*this)).iP);
+              printf("iM = %d\n", this->iM);
             }
   float ld;
   float ff;





More information about the cfe-commits mailing list