diff options
author | Chris Lattner <sabre@nondot.org> | 2007-07-19 22:06:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-07-19 22:06:24 +0000 |
commit | 030d8846c7e520330007087e949f621989876e3a (patch) | |
tree | f9c017db7d6ecb148ba3b7f26d5c04f3498e5cbf | |
parent | aff1edd84aaafef15b737acd8ec61abcca6d6bc3 (diff) |
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
-rw-r--r-- | AST/ASTContext.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
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<uint64_t, unsigned> EltInfo = + getTypeInfo(cast<ArrayType>(T)->getElementType(), L); + + // Get the size of the array. + llvm::APSInt Size(32); + if (!cast<ArrayType>(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<uint64_t, unsigned> EltInfo = + getTypeInfo(cast<VectorType>(T)->getElementType(), L); + Size = EltInfo.first*cast<VectorType>(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 |