Follow Eli's advice and store the VLA size with the native size_t type. Fixes PR3491.

llvm-svn: 63879
This commit is contained in:
Anders Carlsson 2009-02-05 19:43:10 +00:00
parent 4f9d349e07
commit 31f8649f83
3 changed files with 10 additions and 8 deletions

View File

@ -197,6 +197,9 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
llvm::Value *VLASize = EmitVLASize(Ty);
// Downcast the VLA size expression
VLASize = Builder.CreateIntCast(VLASize, llvm::Type::Int32Ty, false, "tmp");
// Allocate memory for the array.
llvm::Value *VLA = Builder.CreateAlloca(llvm::Type::Int8Ty, VLASize, "vla");
DeclPtr = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp");

View File

@ -685,9 +685,7 @@ ScalarExprEmitter::VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E) {
CGF.EmitVLASize(TypeToSize);
}
llvm::Value *VLASize = CGF.GetVLASize(VAT);
return Builder.CreateIntCast(VLASize, ConvertType(E->getType()),
false, "conv");
return CGF.GetVLASize(VAT);
}
}

View File

@ -481,16 +481,17 @@ llvm::Value *CodeGenFunction::EmitVLASize(QualType Ty)
QualType ElemTy = VAT->getElementType();
const llvm::Type *SizeTy = ConvertType(getContext().getSizeType());
if (ElemTy->isVariableArrayType())
ElemSize = EmitVLASize(ElemTy);
else {
// FIXME: We use Int32Ty here because the alloca instruction takes a
// 32-bit integer. What should we do about overflow?
ElemSize = llvm::ConstantInt::get(llvm::Type::Int32Ty,
ElemSize = llvm::ConstantInt::get(SizeTy,
getContext().getTypeSize(ElemTy) / 8);
}
llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr());
NumElements = Builder.CreateIntCast(NumElements, SizeTy, false, "tmp");
SizeEntry = Builder.CreateMul(ElemSize, NumElements);
}