Add the field encoding to struct string_literal_t and merge T_WIDE_STRING_LITERAL...
[cparser] / type.c
diff --git a/type.c b/type.c
index 58c4a34..da737e5 100644 (file)
--- a/type.c
+++ b/type.c
@@ -1114,7 +1114,7 @@ unsigned get_type_size(type_t *type)
                layout_struct_type(&type->compound);
                return type->compound.compound->size;
        case TYPE_FUNCTION:
-               return 0; /* non-const (but "address-const") */
+               return 1; /* strange GNU extensions: sizeof(function) == 1 */
        case TYPE_REFERENCE:
        case TYPE_POINTER:
                return pointer_properties.size;
@@ -1504,6 +1504,7 @@ void layout_struct_type(compound_type_t *type)
                return;
        if (type->compound->layouted)
                return;
+       compound->layouted = true;
 
        il_size_t      offset    = 0;
        il_alignment_t alignment = compound->alignment;
@@ -1511,16 +1512,12 @@ void layout_struct_type(compound_type_t *type)
 
        entity_t *entry = compound->members.entities;
        while (entry != NULL) {
-               if (entry->kind != ENTITY_COMPOUND_MEMBER) {
-                       entry = entry->base.next;
-                       continue;
-               }
+               if (entry->kind != ENTITY_COMPOUND_MEMBER)
+                       goto next;
 
-               type_t *const m_type  = skip_typeref(entry->declaration.type);
-               if (!is_type_valid(m_type)) {
-                       entry = entry->base.next;
-                       continue;
-               }
+               type_t *const m_type = skip_typeref(entry->declaration.type);
+               if (!is_type_valid(m_type))
+                       goto next;
 
                if (entry->compound_member.bitfield) {
                        entry = pack_bitfield_members(&offset, &alignment,
@@ -1544,6 +1541,7 @@ void layout_struct_type(compound_type_t *type)
                entry->compound_member.offset = offset;
                offset += get_type_size(m_type);
 
+next:
                entry = entry->base.next;
        }
 
@@ -1564,7 +1562,6 @@ void layout_struct_type(compound_type_t *type)
 
        compound->size      = offset;
        compound->alignment = alignment;
-       compound->layouted  = true;
 }
 
 void layout_union_type(compound_type_t *type)
@@ -1574,6 +1571,9 @@ void layout_union_type(compound_type_t *type)
        compound_t *compound = type->compound;
        if (! compound->complete)
                return;
+       if (compound->layouted)
+               return;
+       compound->layouted = true;
 
        il_size_t      size      = 0;
        il_alignment_t alignment = compound->alignment;