From: Chris Lattner Date: Sat, 15 Aug 2009 00:03:43 +0000 (+0000) Subject: minor cleanups for VLA stuff. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec18ddd33d5dc2cba5f64fa903bac7a83dc1e01e;p=clang minor cleanups for VLA stuff. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79059 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index a977add65f..e4a83bce02 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -493,19 +493,16 @@ llvm::Value *CodeGenFunction::EmitVLASize(QualType Ty) { llvm::Value *&SizeEntry = VLASizeMap[VAT]; if (!SizeEntry) { - // Get the element size; - llvm::Value *ElemSize; - - QualType ElemTy = VAT->getElementType(); - const llvm::Type *SizeTy = ConvertType(getContext().getSizeType()); + // Get the element size; + QualType ElemTy = VAT->getElementType(); + llvm::Value *ElemSize; if (ElemTy->isVariableArrayType()) ElemSize = EmitVLASize(ElemTy); - else { + else ElemSize = llvm::ConstantInt::get(SizeTy, getContext().getTypeSize(ElemTy) / 8); - } llvm::Value *NumElements = EmitScalarExpr(VAT->getSizeExpr()); NumElements = Builder.CreateIntCast(NumElements, SizeTy, false, "tmp"); @@ -514,14 +511,16 @@ llvm::Value *CodeGenFunction::EmitVLASize(QualType Ty) { } return SizeEntry; - } else if (const ArrayType *AT = dyn_cast(Ty)) { - EmitVLASize(AT->getElementType()); - } else if (const PointerType *PT = Ty->getAs()) - EmitVLASize(PT->getPointeeType()); - else { - assert(0 && "unknown VM type!"); } + if (const ArrayType *AT = dyn_cast(Ty)) { + EmitVLASize(AT->getElementType()); + return 0; + } + + const PointerType *PT = Ty->getAs(); + assert(PT && "unknown VM type!"); + EmitVLASize(PT->getPointeeType()); return 0; }