diff options
author | Anders Carlsson <andersca@mac.com> | 2008-12-12 07:19:02 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2008-12-12 07:19:02 +0000 |
commit | ccbe9200f9f3ec2062a235f7377024db50cbb2f9 (patch) | |
tree | 934e637b2b7c8082f906b07017c977add727704b /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | dcba4a7713035fc6bf3dc5703147e693a1ff3c14 (diff) | |
download | bcm5719-llvm-ccbe9200f9f3ec2062a235f7377024db50cbb2f9.tar.gz bcm5719-llvm-ccbe9200f9f3ec2062a235f7377024db50cbb2f9.zip |
Add map of VLA types and their sizes
llvm-svn: 60939
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index fe88bc91272..bcb51a3efc6 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/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; +} |