}
}
+static llvm::Value *
+EmitBitCastOfLValueToProperType(llvm::IRBuilder<> &Builder,
+ llvm::Value *V, llvm::Type *IRType,
+ llvm::StringRef Name = llvm::StringRef()) {
+ unsigned AS = cast<llvm::PointerType>(V->getType())->getAddressSpace();
+ return Builder.CreateBitCast(V, IRType->getPointerTo(AS), Name);
+}
+
static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF,
const Expr *E, const VarDecl *VD) {
assert((VD->hasExternalStorage() || VD->isFileVarDecl()) &&
llvm::Value *V = CGF.CGM.GetAddrOfGlobalVar(VD);
if (VD->getType()->isReferenceType())
V = CGF.Builder.CreateLoad(V, "tmp");
- unsigned Alignment = CGF.getContext().getDeclAlign(VD).getQuantity();
+ V = EmitBitCastOfLValueToProperType(CGF.Builder, V,
+ CGF.getTypes().ConvertTypeForMem(E->getType()));
+
+ unsigned Alignment = CGF.getContext().getDeclAlign(VD).getQuantity();
LValue LV = CGF.MakeAddrLValue(V, E->getType(), Alignment);
setObjCGCLValueClass(CGF.getContext(), E, LV);
return LV;
if (VD->getType()->isReferenceType())
V = Builder.CreateLoad(V, "tmp");
+ V = EmitBitCastOfLValueToProperType(Builder, V,
+ getTypes().ConvertTypeForMem(E->getType()));
+
LValue LV = MakeAddrLValue(V, E->getType(), Alignment);
if (NonGCable) {
LV.getQuals().removeObjCGCAttr();
// 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 = CGM.getTypes().ConvertTypeForMem(type);
- unsigned AS = cast<llvm::PointerType>(baseAddr->getType())->getAddressSpace();
- addr = Builder.CreateBitCast(addr, llvmType->getPointerTo(AS),
- field->getName());
-
+ addr = EmitBitCastOfLValueToProperType(Builder, addr,
+ CGM.getTypes().ConvertTypeForMem(type),
+ field->getName());
unsigned alignment = getContext().getDeclAlign(field).getQuantity();
LValue LV = MakeAddrLValue(addr, type, alignment);
// Otherwise, return an integer of the target-specified size.
return llvm::IntegerType::get(getLLVMContext(),
(unsigned)Context.getTypeSize(T));
-
}
/// isFuncTypeArgumentConvertible - Return true if the specified type in a
const IncompleteArrayType *A = cast<IncompleteArrayType>(Ty);
assert(A->getIndexTypeCVRQualifiers() == 0 &&
"FIXME: We only handle trivial array types so far!");
- // int X[] -> [0 x int]
- ResultType = llvm::ArrayType::get(ConvertTypeForMem(A->getElementType()),0);
+ // int X[] -> [0 x int], unless the element type is not sized. If it is
+ // unsized (e.g. an incomplete struct) just use [0 x i8].
+ ResultType = ConvertTypeForMem(A->getElementType());
+ if (!ResultType->isSized()) {
+ SkippedLayout = true;
+ ResultType = llvm::Type::getInt8Ty(getLLVMContext());
+ }
+ ResultType = llvm::ArrayType::get(ResultType, 0);
break;
}
case Type::ConstantArray: {