[cfe-commits] r82579 - /cfe/trunk/lib/CodeGen/CGCXXClass.cpp

Anders Carlsson andersca at mac.com
Tue Sep 22 14:58:22 PDT 2009


Author: andersca
Date: Tue Sep 22 16:58:22 2009
New Revision: 82579

URL: http://llvm.org/viewvc/llvm-project?rev=82579&view=rev
Log:
When doing a derived-to-base class and the class offset is 0 we can just do a simple bitcast.

Modified:
    cfe/trunk/lib/CodeGen/CGCXXClass.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXXClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXXClass.cpp Tue Sep 22 16:58:22 2009
@@ -77,10 +77,18 @@
   if (ClassDecl == BaseClassDecl)
     return BaseValue;
 
+  QualType BTy =
+    getContext().getCanonicalType(
+      getContext().getTypeDeclType(const_cast<CXXRecordDecl*>(BaseClassDecl)));
+  const llvm::Type *BasePtrTy = llvm::PointerType::getUnqual(ConvertType(BTy));
 
   uint64_t Offset = ComputeBaseClassOffset(getContext(), 
                                            ClassDecl, BaseClassDecl);
-
+  if (!Offset) {
+    // Just cast back.
+    return Builder.CreateBitCast(BaseValue, BasePtrTy);
+  }
+  
   llvm::BasicBlock *CastNull = 0;
   llvm::BasicBlock *CastNotNull = 0;
   llvm::BasicBlock *CastEnd = 0;
@@ -108,13 +116,8 @@
   BaseValue = Builder.CreateBitCast(BaseValue, Int8PtrTy);
   BaseValue = Builder.CreateGEP(BaseValue, OffsetVal, "add.ptr");
   
-  QualType BTy =
-    getContext().getCanonicalType(
-      getContext().getTypeDeclType(const_cast<CXXRecordDecl*>(BaseClassDecl)));
-  
   // Cast back.
-  const llvm::Type *BasePtr = llvm::PointerType::getUnqual(ConvertType(BTy));
-  BaseValue = Builder.CreateBitCast(BaseValue, BasePtr);
+  BaseValue = Builder.CreateBitCast(BaseValue, BasePtrTy);
  
   if (NullCheckValue) {
     Builder.CreateBr(CastEnd);





More information about the cfe-commits mailing list