forked from OSchip/llvm-project
Handle typedefs to VLAs (Emit the size expr when we encounter the typedef
llvm-svn: 61290
This commit is contained in:
parent
fbef9c208f
commit
5d985f5f16
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -428,26 +428,26 @@ 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());
|
||||
|
||||
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());
|
||||
|
|
|
@ -2184,8 +2184,7 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
|
|||
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];
|
||||
|
|
Loading…
Reference in New Issue