From fcdbb93749ed69aa9022437052c390522355ec3d Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 20 Dec 2008 21:51:53 +0000 Subject: Handle typedefs to VLAs (Emit the size expr when we encounter the typedef git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61290 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenFunction.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'lib/CodeGen/CodeGenFunction.cpp') diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 73b71b2f62..2ef4bcf981 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -428,25 +428,25 @@ llvm::Value *CodeGenFunction::EmitVLASize(QualType Ty) if (const VariableArrayType *VAT = getContext().getAsVariableArrayType(Ty)) { llvm::Value *&SizeEntry = VLASizeMap[VAT]; - assert(!SizeEntry && "Must not emit the same VLA size more than once!"); + if (!SizeEntry) { + // Get the element size; + llvm::Value *ElemSize; - // Get the element size; - llvm::Value *ElemSize; + QualType ElemTy = VAT->getElementType(); - QualType ElemTy = VAT->getElementType(); - - 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, - getContext().getTypeSize(ElemTy) / 8); - } + 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, + getContext().getTypeSize(ElemTy) / 8); + } - llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr()); + llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr()); - SizeEntry = Builder.CreateMul(ElemSize, NumElements); + SizeEntry = Builder.CreateMul(ElemSize, NumElements); + } return SizeEntry; } else if (const PointerType *PT = Ty->getAsPointerType()) -- cgit v1.2.3-18-g5258