f19c88bc0508 — Leonard Ritter 15 days ago
* structs and arrays report the right size when elements are references
M src/type.cpp +10 -0
@@ 277,6 277,11 @@ SCOPES_RESULT(size_t) size_of(const Type
     SCOPES_ERROR(OpaqueType, T);
 }
 
+SCOPES_RESULT(size_t) qualified_size_of(const Type *T) {
+    SCOPES_RESULT_TYPE(size_t);
+    return size_of(SCOPES_GET_RESULT(qualified_storage_type(T)));
+}
+
 SCOPES_RESULT(size_t) align_of(const Type *T) {
     SCOPES_RESULT_TYPE(size_t);
     switch(T->kind()) {

          
@@ 309,6 314,11 @@ SCOPES_RESULT(size_t) align_of(const Typ
     SCOPES_ERROR(OpaqueType, T);
 }
 
+SCOPES_RESULT(size_t) qualified_align_of(const Type *T) {
+    SCOPES_RESULT_TYPE(size_t);
+    return align_of(SCOPES_GET_RESULT(qualified_storage_type(T)));
+}
+
 const Type *superof(const Type *T) {
     switch(T->kind()) {
     case TK_Qualify: return TYPE_Qualify;

          
M src/type.hpp +2 -0
@@ 184,7 184,9 @@ B_TYPES()
 bool is_opaque(const Type *T);
 TypeKind storage_kind(const Type *T);
 SCOPES_RESULT(size_t) size_of(const Type *T);
+SCOPES_RESULT(size_t) qualified_size_of(const Type *T);
 SCOPES_RESULT(size_t) align_of(const Type *T);
+SCOPES_RESULT(size_t) qualified_align_of(const Type *T);
 const Type *superof(const Type *T);
 void stream_type_name(StyledStream &ss, const Type *T);
 bool is_returning(const Type *T);

          
M src/type/array_type.cpp +1 -1
@@ 50,7 50,7 @@ void ArrayType::stream_name(StyledStream
 ArrayType::ArrayType(const Type *_element_type, size_t _count)
     : ArrayLikeType(TK_Array, _element_type, _count) {
     size = stride * count();
-    align = align_of(element_type).assert_ok();
+    align = qualified_align_of(element_type).assert_ok();
 }
 
 //------------------------------------------------------------------------------

          
M src/type/sized_storage_type.cpp +1 -1
@@ 25,7 25,7 @@ bool ArrayLikeType::classof(const Type *
 
 ArrayLikeType::ArrayLikeType(TypeKind kind, const Type *_element_type, size_t count)
     : CompositeType(kind), element_type(_element_type), _count(count) {
-    stride = size_of(element_type).assert_ok();
+    stride = qualified_size_of(element_type).assert_ok();
 }
 
 SCOPES_RESULT(void *) ArrayLikeType::getelementptr(void *src, size_t i) const {

          
M src/type/tuple_type.cpp +3 -3
@@ 83,7 83,7 @@ TupleType::TupleType(const Types &_value
         for (size_t i = 0; i < values.size(); ++i) {
             const Type *ET = values[i];
             offsets[i] = sz;
-            sz += size_of(ET).assert_ok();
+            sz += qualified_size_of(ET).assert_ok();
         }
         size = sz;
         align = 1;

          
@@ 91,11 91,11 @@ TupleType::TupleType(const Types &_value
         size_t al = 1;
         for (size_t i = 0; i < values.size(); ++i) {
             const Type *ET = values[i];
-            size_t etal = align_of(ET).assert_ok();
+            size_t etal = qualified_align_of(ET).assert_ok();
             sz = scopes::align(sz, etal);
             offsets[i] = sz;
             al = std::max(al, etal);
-            sz += size_of(ET).assert_ok();
+            sz += qualified_size_of(ET).assert_ok();
         }
         size = scopes::align(sz, al);
         align = al;