[cfe-commits] r40068 - /cfe/trunk/AST/ASTContext.cpp
Chris Lattner
sabre at nondot.org
Thu Jul 19 15:06:24 PDT 2007
Author: lattner
Date: Thu Jul 19 17:06:24 2007
New Revision: 40068
URL: http://llvm.org/viewvc/llvm-project?rev=40068&view=rev
Log:
implement size/alignment analysis for arrays and vectors. This gets carbon.h working again.
Modified:
cfe/trunk/AST/ASTContext.cpp
Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=40068&r1=40067&r2=40068&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Thu Jul 19 17:06:24 2007
@@ -157,14 +157,32 @@
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
More information about the cfe-commits
mailing list