diff options
author | Anders Carlsson <andersca@mac.com> | 2008-12-20 20:46:34 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2008-12-20 20:46:34 +0000 |
commit | 8a01b79274be3a2128be030f1ef3180d26e7317c (patch) | |
tree | 7a0c115c5628f3e4d95dac918ab5203e46e6a274 /clang/lib/CodeGen/CGDecl.cpp | |
parent | e388a5bf44aba581bc17a40235b630c6383ae931 (diff) | |
download | bcm5719-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/CGDecl.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 7f4e34d0f9a..e8084dcf179 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -160,9 +160,10 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) { D.getStorageClass() == VarDecl::Register ? ".reg." : ".auto."; DeclPtr = GenerateStaticBlockVarDecl(D, true, Class); } + + if (Ty->isVariablyModifiedType()) + EmitVLASize(Ty); } else { - const VariableArrayType *VAT = getContext().getAsVariableArrayType(Ty); - if (!StackSaveValues.back()) { // Save the stack. const llvm::Type *LTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); @@ -180,7 +181,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) { const llvm::Type *LElemPtrTy = llvm::PointerType::get(LElemTy, D.getType().getAddressSpace()); - llvm::Value *VLASize = EmitVLASize(VAT); + llvm::Value *VLASize = EmitVLASize(Ty); // Allocate memory for the array. llvm::Value *VLA = Builder.CreateAlloca(llvm::Type::Int8Ty, VLASize, "vla"); |