summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-12-20 20:46:34 +0000
committerAnders Carlsson <andersca@mac.com>2008-12-20 20:46:34 +0000
commit8a01b79274be3a2128be030f1ef3180d26e7317c (patch)
tree7a0c115c5628f3e4d95dac918ab5203e46e6a274 /clang/lib/CodeGen/CodeGenFunction.cpp
parente388a5bf44aba581bc17a40235b630c6383ae931 (diff)
downloadbcm5719-llvm-8a01b79274be3a2128be030f1ef3180d26e7317c.tar.gz
bcm5719-llvm-8a01b79274be3a2128be030f1ef3180d26e7317c.zip
Change EmitVLASize to take a QualType that must be a variably modified type.
Emit the size even if the declared type is a variably modified type. This lets us handle void f(int n) { int (*a)[n]; printf("size: %d\n", sizeof(*a)); } llvm-svn: 61285
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp53
1 files changed, 32 insertions, 21 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 4a3bb3f6caa..6f32553118b 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -410,29 +410,40 @@ llvm::Value *CodeGenFunction::GetVLASize(const VariableArrayType *VAT)
return SizeEntry;
}
-llvm::Value *CodeGenFunction::EmitVLASize(const VariableArrayType *VAT)
+llvm::Value *CodeGenFunction::EmitVLASize(QualType Ty)
{
- llvm::Value *&SizeEntry = VLASizeMap[VAT];
-
- assert(!SizeEntry && "Must not emit the same VLA size more than once!");
- // Get the element size;
- llvm::Value *ElemSize;
+ assert(Ty->isVariablyModifiedType() &&
+ "Must pass variably modified type to EmitVLASizes!");
- QualType ElemTy = VAT->getElementType();
-
- if (const VariableArrayType *ElemVAT =
- getContext().getAsVariableArrayType(ElemTy))
- ElemSize = EmitVLASize(ElemVAT);
+ if (const VariableArrayType *VAT = getContext().getAsVariableArrayType(Ty)) {
+ llvm::Value *&SizeEntry = VLASizeMap[VAT];
+
+ assert(!SizeEntry && "Must not emit the same VLA size more than once!");
+
+ // Get the element size;
+ llvm::Value *ElemSize;
+
+ 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);
+ }
+
+ llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr());
+
+ SizeEntry = Builder.CreateMul(ElemSize, NumElements);
+
+ return SizeEntry;
+ } else if (const PointerType *PT = Ty->getAsPointerType())
+ EmitVLASize(PT->getPointeeType());
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(0 && "unknown VM type!");
}
-
- llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr());
-
- SizeEntry = Builder.CreateMul(ElemSize, NumElements);
-
- return SizeEntry;
+
+ return 0;
}
OpenPOWER on IntegriCloud