more work on type size
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 15 Sep 2008 14:57:42 +0000 (14:57 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 15 Sep 2008 14:57:42 +0000 (14:57 +0000)
[r21978]

ast2firm.c
parser.c
type.c
type_t.h

index 46e48d3..d7f7b1f 100644 (file)
@@ -530,7 +530,7 @@ static ir_type *create_bitfield_type(bitfield_type_t *const type)
        assert(base->kind == TYPE_ATOMIC || base->kind == TYPE_ENUM);
        ir_type *irbase = get_ir_type(base);
 
-       unsigned size = fold_constant(type->size);
+       unsigned size = type->bit_size;
 
        assert(!is_type_float(base));
        if (is_type_signed(base)) {
@@ -650,7 +650,7 @@ static ir_type *create_compound_type(compound_type_t *type, ir_type *irtype,
                size_t base;
                size_t bits_remainder;
                if (entry_type->kind == TYPE_BITFIELD) {
-                       size_t size_bits      = fold_constant(entry_type->bitfield.size);
+                       size_t size_bits      = entry_type->bitfield.bit_size;
                        size_t rest_size_bits = (entry_alignment - misalign)*8 - bit_offset;
 
                        if (size_bits > rest_size_bits) {
index 09c521d..7aaa859 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -3129,33 +3129,38 @@ static void finish_struct_type(compound_type_t *type) {
        if (! struct_decl->init.complete)
                return;
 
-       il_size_t      size      = 0;
-       il_size_t      new_size;
-       il_alignment_t alignment = 1;
-       bool           need_pad  = false;
+       il_size_t      size           = 0;
+       il_size_t      offset;
+       il_alignment_t alignment      = 1;
+       bool           need_pad       = false;
 
        declaration_t *entry = struct_decl->scope.declarations;
        for (; entry != NULL; entry = entry->next) {
                if (entry->namespc != NAMESPACE_NORMAL)
                        continue;
 
-               type_t         *m_type      = skip_typeref(entry->type);
-               il_alignment_t  m_alignment = m_type->base.alignment;
-
-               new_size = (size + m_alignment - 1) & -m_alignment;
+               type_t *m_type = skip_typeref(entry->type);
+               if (! is_type_valid(m_type)) {
+                       /* simply ignore errors here */
+                       continue;
+               }
+               il_alignment_t m_alignment = m_type->base.alignment;
                if (m_alignment > alignment)
                        alignment = m_alignment;
-               if (new_size > size)
+
+               offset = (size + m_alignment - 1) & -m_alignment;
+
+               if (offset > size)
                        need_pad = true;
-               entry->offset = new_size;
-               size = new_size + m_type->base.size;
+               entry->offset = offset;
+               size = offset + m_type->base.size;
        }
        if (type->base.alignment != 0) {
                alignment = type->base.alignment;
        }
 
-       new_size = (size + alignment - 1) & -alignment;
-       if (new_size > size)
+       offset = (size + alignment - 1) & -alignment;
+       if (offset > size)
                need_pad = true;
 
        if (warning.padded && need_pad) {
@@ -3168,7 +3173,7 @@ static void finish_struct_type(compound_type_t *type) {
                        type, struct_decl->symbol);
        }
 
-       type->base.size      = new_size;
+       type->base.size      = offset;
        type->base.alignment = alignment;
 }
 
@@ -3192,6 +3197,8 @@ static void finish_union_type(compound_type_t *type) {
                        continue;
 
                type_t *m_type = skip_typeref(entry->type);
+               if (! is_type_valid(m_type))
+                       continue;
 
                entry->offset = 0;
                if (m_type->base.size > size)
@@ -5515,8 +5522,12 @@ static type_t *make_bitfield_type(type_t *base_type, expression_t *size,
 {
        type_t *type = allocate_type_zero(TYPE_BITFIELD, source_position);
 
-       type->bitfield.base_type = base_type;
-       type->bitfield.size      = size;
+       type->bitfield.base_type       = base_type;
+       type->bitfield.size_expression = size;
+
+       if (is_constant_expression(size)) {
+               type->bitfield.bit_size = fold_constant(size);
+       }
 
        return type;
 }
diff --git a/type.c b/type.c
index c55b777..3c6bed6 100644 (file)
--- a/type.c
+++ b/type.c
@@ -435,7 +435,7 @@ static void print_array_type_post(const array_type_t *type)
 static void print_bitfield_type_post(const bitfield_type_t *type)
 {
        fputs(" : ", out);
-       print_expression(type->size);
+       print_expression(type->size_expression);
        intern_print_type_post(type->base_type, false);
 }
 
index ec5b9a2..894270d 100644 (file)
--- a/type_t.h
+++ b/type_t.h
@@ -141,6 +141,7 @@ struct function_type_t {
 
 struct compound_type_t {
        type_base_t    base;
+       unsigned       packed:1;       /** Set if packed was specified. */
        /** the declaration of the compound type, the scope of the declaration
         *  contains the compound entries. */
        declaration_t *declaration;
@@ -170,7 +171,8 @@ struct typeof_type_t {
 struct bitfield_type_t {
        type_base_t   base;
        type_t       *base_type;
-       expression_t *size;
+       expression_t *size_expression; /**< The expression for the bit size. */
+       il_size_t     bit_size;        /**< Size of this bitfield in bits. */
 };
 
 union type_t {