aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-12-20 21:51:53 +0000
committerAnders Carlsson <andersca@mac.com>2008-12-20 21:51:53 +0000
commitfcdbb93749ed69aa9022437052c390522355ec3d (patch)
treed15a415fc2ca5e6e2e1f3baea6505215672e7d6e /lib/CodeGen
parent7e63b8527fa0b065802fc6cb8cb6124d7c23c4a2 (diff)
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
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGDecl.cpp9
-rw-r--r--lib/CodeGen/CodeGenFunction.cpp30
2 files changed, 23 insertions, 16 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index e8084dcf17..86bc347576 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -31,7 +31,6 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
default: assert(0 && "Unknown decl kind!");
case Decl::ParmVar:
assert(0 && "Parmdecls should not be in declstmts!");
- case Decl::Typedef: // typedef int X;
case Decl::Function: // void X();
case Decl::Record: // struct/union/class X;
case Decl::Enum: // enum X;
@@ -46,6 +45,14 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
"Should not see file-scope variables inside a function!");
return EmitBlockVarDecl(VD);
}
+
+ case Decl::Typedef: { // typedef int X;
+ const TypedefDecl &TD = cast<TypedefDecl>(D);
+ QualType Ty = TD.getUnderlyingType();
+
+ if (Ty->isVariablyModifiedType())
+ EmitVLASize(Ty);
+ }
}
}
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())