[cfe-commits] r134865 - /cfe/trunk/lib/CodeGen/CGExpr.cpp

Chris Lattner sabre at nondot.org
Sat Jul 9 22:53:24 PDT 2011


Author: lattner
Date: Sun Jul 10 00:53:24 2011
New Revision: 134865

URL: http://llvm.org/viewvc/llvm-project?rev=134865&view=rev
Log:
enhance EmitLValueForFieldInitialization to do the proper pointer adjustment, allowing
us to revert the other half of r134860.  Now things are back to a relatively tidy state.

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

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=134865&r1=134864&r2=134865&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sun Jul 10 00:53:24 2011
@@ -764,14 +764,6 @@
                                         llvm::MDNode *TBAAInfo) {
   Value = EmitToMemory(Value, Ty);
   
-  // If this is a pointer r-value, make sure that it has the right scalar type.
-  if (isa<llvm::PointerType>(Value->getType())) {
-    llvm::Type *EltTy =
-      cast<llvm::PointerType>(Addr->getType())->getElementType();
-    if (EltTy != Value->getType())
-      Value = Builder.CreateBitCast(Value, EltTy);
-  }
-  
   llvm::StoreInst *Store = Builder.CreateStore(Value, Addr, Volatile);
   if (Alignment)
     Store->setAlignment(Alignment);
@@ -1880,9 +1872,17 @@
     CGM.getTypes().getCGRecordLayout(Field->getParent());
   unsigned idx = RL.getLLVMFieldNo(Field);
   llvm::Value *V = Builder.CreateStructGEP(BaseValue, idx, "tmp");
-
   assert(!FieldType.getObjCGCAttr() && "fields cannot have GC attrs");
 
+  
+  // Make sure that the address is pointing to the right type.  This is critical
+  // for both unions and structs.  A union needs a bitcast, a struct element
+  // will need a bitcast if the LLVM type laid out doesn't match the desired
+  // type.
+  const llvm::Type *llvmType = ConvertTypeForMem(FieldType);
+  unsigned AS = cast<llvm::PointerType>(V->getType())->getAddressSpace();
+  V = Builder.CreateBitCast(V, llvmType->getPointerTo(AS));
+  
   unsigned Alignment = getContext().getDeclAlign(Field).getQuantity();
   return MakeAddrLValue(V, FieldType, Alignment);
 }





More information about the cfe-commits mailing list