[cfe-commits] r61290 - in /cfe/trunk/lib: CodeGen/CGDecl.cpp CodeGen/CodeGenFunction.cpp Sema/SemaDecl.cpp
Anders Carlsson
andersca at mac.com
Sat Dec 20 13:51:54 PST 2008
Author: andersca
Date: Sat Dec 20 15:51:53 2008
New Revision: 61290
URL: http://llvm.org/viewvc/llvm-project?rev=61290&view=rev
Log:
Handle typedefs to VLAs (Emit the size expr when we encounter the typedef
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=61290&r1=61289&r2=61290&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat Dec 20 15:51:53 2008
@@ -31,7 +31,6 @@
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 @@
"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);
+ }
}
}
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=61290&r1=61289&r2=61290&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sat Dec 20 15:51:53 2008
@@ -428,26 +428,26 @@
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;
+
+ 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);
+ }
- // Get the element size;
- llvm::Value *ElemSize;
+ llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr());
- 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);
+ SizeEntry = Builder.CreateMul(ElemSize, NumElements);
}
- llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr());
-
- SizeEntry = Builder.CreateMul(ElemSize, NumElements);
-
return SizeEntry;
} else if (const PointerType *PT = Ty->getAsPointerType())
EmitVLASize(PT->getPointeeType());
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=61290&r1=61289&r2=61290&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Dec 20 15:51:53 2008
@@ -2184,8 +2184,7 @@
QualType T = IDecl->getType();
if (T->isVariableArrayType()) {
- const VariableArrayType *VAT =
- cast<VariableArrayType>(T.getUnqualifiedType());
+ const VariableArrayType *VAT = Context.getAsVariableArrayType(T);
// FIXME: This won't give the correct result for
// int a[10][n];
More information about the cfe-commits
mailing list