From dcc90d87e6430c643b4311ae5b0089535bca41f7 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 12 Dec 2008 07:19:02 +0000 Subject: Add map of VLA types and their sizes git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60939 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenFunction.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/CodeGen/CodeGenFunction.cpp') diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index fe88bc9127..bcb51a3efc 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -401,3 +401,30 @@ llvm::Value *CodeGenFunction::EmitVAArg(llvm::Value *VAListAddr, QualType Ty) return AddrTyped; } +llvm::Value *CodeGenFunction::GetVLASize(const VariableArrayType *VAT) +{ + llvm::Value *&SizeEntry = VLASizeMap[VAT]; + + if (!SizeEntry) { + // Get the element size; + llvm::Value *ElemSize; + + QualType ElemTy = VAT->getElementType(); + + if (const VariableArrayType *ElemVAT = + getContext().getAsVariableArrayType(ElemTy)) + ElemSize = GetVLASize(ElemVAT); + 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, + getContext().getTypeSize(ElemTy) / 8); + } + + llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr()); + + SizeEntry = Builder.CreateMul(ElemSize, NumElements); + } + + return SizeEntry; +} -- cgit v1.2.3-18-g5258