[cfe-commits] r102273 - in /cfe/trunk/lib/CodeGen: CGClass.cpp CGExpr.cpp CGExprScalar.cpp CodeGenFunction.h CodeGenModule.h

Anders Carlsson andersca at mac.com
Sat Apr 24 14:23:59 PDT 2010


Author: andersca
Date: Sat Apr 24 16:23:59 2010
New Revision: 102273

URL: http://llvm.org/viewvc/llvm-project?rev=102273&view=rev
Log:
Change CodeGenFunction::GetAddressOfDerivedClass to take a BasePath.

Modified:
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=102273&r1=102272&r2=102273&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Sat Apr 24 16:23:59 2010
@@ -74,6 +74,23 @@
 }
 
 llvm::Constant *
+CodeGenModule::GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
+                                        const CXXBaseSpecifierArray &BasePath) {
+  assert(!BasePath.empty() && "Base path should not be empty!");
+
+  uint64_t Offset = 
+    ComputeNonVirtualBaseClassOffset(getContext(), ClassDecl, 
+                                     BasePath.begin(), BasePath.end());
+  if (!Offset)
+    return 0;
+  
+  const llvm::Type *PtrDiffTy = 
+  Types.ConvertType(getContext().getPointerDiffType());
+  
+  return llvm::ConstantInt::get(PtrDiffTy, Offset);
+}  
+
+llvm::Constant *
 CodeGenModule::GetNonVirtualBaseClassOffset(const CXXRecordDecl *Class,
                                             const CXXRecordDecl *BaseClass) {
   if (Class == BaseClass)
@@ -336,21 +353,18 @@
 
 llvm::Value *
 CodeGenFunction::GetAddressOfDerivedClass(llvm::Value *Value,
-                                          const CXXRecordDecl *Class,
                                           const CXXRecordDecl *DerivedClass,
+                                          const CXXBaseSpecifierArray &BasePath,
                                           bool NullCheckValue) {
+  assert(!BasePath.empty() && "Base path should not be empty!");
+
   QualType DerivedTy =
     getContext().getCanonicalType(
     getContext().getTypeDeclType(const_cast<CXXRecordDecl*>(DerivedClass)));
   const llvm::Type *DerivedPtrTy = ConvertType(DerivedTy)->getPointerTo();
   
-  if (Class == DerivedClass) {
-    // Just cast back.
-    return Builder.CreateBitCast(Value, DerivedPtrTy);
-  }
-
   llvm::Value *NonVirtualOffset =
-    CGM.GetNonVirtualBaseClassOffset(DerivedClass, Class);
+    CGM.GetNonVirtualBaseClassOffset(DerivedClass, BasePath);
   
   if (!NonVirtualOffset) {
     // No offset, we can just cast back.

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=102273&r1=102272&r2=102273&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sat Apr 24 16:23:59 2010
@@ -1693,11 +1693,6 @@
   case CastExpr::CK_ToUnion:
     return EmitAggExprToLValue(E);
   case CastExpr::CK_BaseToDerived: {
-    const RecordType *BaseClassTy = 
-      E->getSubExpr()->getType()->getAs<RecordType>();
-    CXXRecordDecl *BaseClassDecl = 
-      cast<CXXRecordDecl>(BaseClassTy->getDecl());
-    
     const RecordType *DerivedClassTy = E->getType()->getAs<RecordType>();
     CXXRecordDecl *DerivedClassDecl = 
       cast<CXXRecordDecl>(DerivedClassTy->getDecl());
@@ -1706,8 +1701,8 @@
     
     // Perform the base-to-derived conversion
     llvm::Value *Derived = 
-      GetAddressOfDerivedClass(LV.getAddress(), BaseClassDecl, 
-                               DerivedClassDecl, /*NullCheckValue=*/false);
+      GetAddressOfDerivedClass(LV.getAddress(), DerivedClassDecl, 
+                               E->getBasePath(),/*NullCheckValue=*/false);
     
     return LValue::MakeAddr(Derived, MakeQualifiers(E->getType()));
   }

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=102273&r1=102272&r2=102273&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Apr 24 16:23:59 2010
@@ -822,16 +822,12 @@
     return Visit(const_cast<Expr*>(E));
 
   case CastExpr::CK_BaseToDerived: {
-    const CXXRecordDecl *BaseClassDecl = 
-      E->getType()->getCXXRecordDeclForPointerType();
     const CXXRecordDecl *DerivedClassDecl = 
       DestTy->getCXXRecordDeclForPointerType();
     
-    Value *Src = Visit(const_cast<Expr*>(E));
-    
-    bool NullCheckValue = ShouldNullCheckClassCastValue(CE);
-    return CGF.GetAddressOfDerivedClass(Src, BaseClassDecl, DerivedClassDecl, 
-                                        NullCheckValue);
+    return CGF.GetAddressOfDerivedClass(Visit(E), DerivedClassDecl, 
+                                        CE->getBasePath(), 
+                                        ShouldNullCheckClassCastValue(CE));
   }
   case CastExpr::CK_UncheckedDerivedToBase:
   case CastExpr::CK_DerivedToBase: {

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=102273&r1=102272&r2=102273&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Apr 24 16:23:59 2010
@@ -793,8 +793,8 @@
                                      bool NullCheckValue);
 
   llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value,
-                                        const CXXRecordDecl *ClassDecl,
                                         const CXXRecordDecl *DerivedClassDecl,
+                                        const CXXBaseSpecifierArray &BasePath,
                                         bool NullCheckValue);
 
   llvm::Value *GetVirtualBaseClassOffset(llvm::Value *This,

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=102273&r1=102272&r2=102273&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Sat Apr 24 16:23:59 2010
@@ -245,7 +245,10 @@
   llvm::Constant *
   GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
                                const CXXRecordDecl *BaseClassDecl);
-
+  llvm::Constant *
+  GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
+                               const CXXBaseSpecifierArray &BasePath);
+  
   /// 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.





More information about the cfe-commits mailing list