]> granicus.if.org Git - clang/commitdiff
implement size/alignment analysis for arrays and vectors. This gets carbon.h working...
authorChris Lattner <sabre@nondot.org>
Thu, 19 Jul 2007 22:06:24 +0000 (22:06 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 19 Jul 2007 22:06:24 +0000 (22:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40068 91177308-0d34-0410-b5e6-96231b3b80d8

AST/ASTContext.cpp

index f45051bf3659dfc6142939dfb23909f7cdb28d78..0de2d5e4e657be9836297cda15f996f4e741053f 100644 (file)
@@ -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