[cfe-commits] r63879 - in /cfe/trunk/lib/CodeGen: CGDecl.cpp CGExprScalar.cpp CodeGenFunction.cpp
Anders Carlsson
andersca at mac.com
Thu Feb 5 11:43:10 PST 2009
Author: andersca
Date: Thu Feb 5 13:43:10 2009
New Revision: 63879
URL: http://llvm.org/viewvc/llvm-project?rev=63879&view=rev
Log:
Follow Eli's advice and store the VLA size with the native size_t type. Fixes PR3491.
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=63879&r1=63878&r2=63879&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Thu Feb 5 13:43:10 2009
@@ -197,6 +197,9 @@
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");
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=63879&r1=63878&r2=63879&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Feb 5 13:43:10 2009
@@ -685,9 +685,7 @@
CGF.EmitVLASize(TypeToSize);
}
- llvm::Value *VLASize = CGF.GetVLASize(VAT);
- return Builder.CreateIntCast(VLASize, ConvertType(E->getType()),
- false, "conv");
+ return CGF.GetVLASize(VAT);
}
}
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=63879&r1=63878&r2=63879&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Thu Feb 5 13:43:10 2009
@@ -480,18 +480,19 @@
llvm::Value *ElemSize;
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);
}
More information about the cfe-commits
mailing list