From: Chris Lattner Date: Thu, 19 Jul 2007 22:06:24 +0000 (+0000) Subject: implement size/alignment analysis for arrays and vectors. This gets carbon.h working... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=030d8846c7e520330007087e949f621989876e3a;p=clang implement size/alignment analysis for arrays and vectors. This gets carbon.h working again. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40068 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp index f45051bf36..0de2d5e4e6 100644 --- a/AST/ASTContext.cpp +++ b/AST/ASTContext.cpp @@ -157,14 +157,32 @@ ASTContext::getTypeInfo(QualType T, SourceLocation L) { uint64_t Size; unsigned Align; switch (T->getTypeClass()) { + case Type::TypeName: assert(0 && "Not a canonical type!"); case Type::FunctionNoProto: case Type::FunctionProto: assert(0 && "Incomplete types have no size!"); default: - case Type::Array: - case Type::Vector: - case Type::TypeName: - assert(0 && "Unimplemented type sizes!"); + case Type::Array: { + std::pair EltInfo = + getTypeInfo(cast(T)->getElementType(), L); + + // Get the size of the array. + llvm::APSInt Size(32); + if (!cast(T)->getSizeExpr()->isIntegerConstantExpr(Size, *this)) + assert(0 && "VLAs not implemented yet!"); + + Size = EltInfo.first*Size.getZExtValue(); + Align = EltInfo.second; + break; + } + case Type::Vector: { + std::pair EltInfo = + getTypeInfo(cast(T)->getElementType(), L); + Size = EltInfo.first*cast(T)->getNumElements(); + // FIXME: Vector alignment is not the alignment of its elements. + Align = EltInfo.second; + break; + } case Type::Builtin: { // FIXME: need to use TargetInfo to derive the target specific sizes. This