diff options
author | Chris Lattner <sabre@nondot.org> | 2011-07-10 05:53:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-07-10 05:53:24 +0000 |
commit | 1b5ba858e4628049a7105257fa712b4ab93c0a62 (patch) | |
tree | 9ff28cbdef46c735ef81b72543e02c18427560dc /lib/CodeGen/CGExpr.cpp | |
parent | aa01d26e6bf177aba365a7adce62cea6ceccfa5b (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134865 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 0a42a5f519..e1d93095bd 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -764,14 +764,6 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, 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 @@ CodeGenFunction::EmitLValueForFieldInitialization(llvm::Value *BaseValue, 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); } |