diff options
author | Anders Carlsson <andersca@mac.com> | 2008-12-20 20:27:15 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2008-12-20 20:27:15 +0000 |
commit | f666b7780d04186521adcaedb0e15dfa4d5e6933 (patch) | |
tree | 9d9e6b9810fa955c54d37138ca5c9956d16a03d2 /lib/CodeGen/CodeGenFunction.cpp | |
parent | eb91f0ecb420f481811f8812ac4d39087e8dd754 (diff) |
Split up emitting of VLA sizes and getting the size of a VLA.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61284 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index bcb51a3efc..4a3bb3f6ca 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -401,30 +401,38 @@ 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); - } + assert(SizeEntry && "Did not emit size for type"); + return SizeEntry; +} - llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr()); +llvm::Value *CodeGenFunction::EmitVLASize(const VariableArrayType *VAT) +{ + llvm::Value *&SizeEntry = VLASizeMap[VAT]; - SizeEntry = Builder.CreateMul(ElemSize, NumElements); + assert(!SizeEntry && "Must not emit the same VLA size more than once!"); + // Get the element size; + llvm::Value *ElemSize; + + QualType ElemTy = VAT->getElementType(); + + if (const VariableArrayType *ElemVAT = + getContext().getAsVariableArrayType(ElemTy)) + ElemSize = EmitVLASize(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; } |