Remove gcse optimization
[cparser] / type.c
diff --git a/type.c b/type.c
index 27ec551..7a406bd 100644 (file)
--- a/type.c
+++ b/type.c
@@ -204,7 +204,8 @@ void init_types(void)
        }
 
        unsigned int_size   = machine_size < 32 ? 2 : 4;
-       unsigned long_size  = machine_size < 64 ? 4 : 8;
+       /* long is always 32bit on windows */
+       unsigned long_size  = c_mode & _MS ? 4 : (machine_size < 64 ? 4 : 8);
        unsigned llong_size = machine_size < 32 ? 4 : 8;
 
        props[ATOMIC_TYPE_INT].size            = int_size;
@@ -222,14 +223,22 @@ void init_types(void)
 
        /* TODO: backend specific, need a way to query the backend for this.
         * The following are good settings for x86 */
-       props[ATOMIC_TYPE_FLOAT].alignment       = 4;
-       props[ATOMIC_TYPE_DOUBLE].alignment      = 4;
-       props[ATOMIC_TYPE_LONG_DOUBLE].alignment = 4;
-       props[ATOMIC_TYPE_LONGLONG].alignment    = 4;
-       props[ATOMIC_TYPE_ULONGLONG].alignment   = 4;
-       if (firm_opt.os_support == OS_SUPPORT_MACHO) {
-               props[ATOMIC_TYPE_LONG_DOUBLE].size      = 16;
-               props[ATOMIC_TYPE_LONG_DOUBLE].alignment = 16;
+       if (machine_size <= 32) {
+               props[ATOMIC_TYPE_FLOAT].alignment       = 4;
+               props[ATOMIC_TYPE_DOUBLE].alignment      = 4;
+               props[ATOMIC_TYPE_LONG_DOUBLE].alignment = 4;
+               props[ATOMIC_TYPE_LONGLONG].alignment    = 4;
+               props[ATOMIC_TYPE_ULONGLONG].alignment   = 4;
+       } else {
+               props[ATOMIC_TYPE_FLOAT].alignment       = 4;
+               props[ATOMIC_TYPE_DOUBLE].alignment      = 8;
+               props[ATOMIC_TYPE_LONG_DOUBLE].alignment = 8;
+               props[ATOMIC_TYPE_LONGLONG].alignment    = 8;
+               props[ATOMIC_TYPE_ULONGLONG].alignment   = 8;
+       }
+       if (force_long_double_size > 0) {
+               props[ATOMIC_TYPE_LONG_DOUBLE].size      = force_long_double_size;
+               props[ATOMIC_TYPE_LONG_DOUBLE].alignment = force_long_double_size;
        }
 
        /* TODO: make this configurable for platforms which do not use byte sized
@@ -773,11 +782,6 @@ void print_type(const type_t *const type)
 void print_type_ext(const type_t *const type, const symbol_t *symbol,
                     const scope_t *parameters)
 {
-       if (type == NULL) {
-               print_string("nil type");
-               return;
-       }
-
        intern_print_type_pre(type);
        if (symbol != NULL) {
                print_string(" ");
@@ -1009,9 +1013,9 @@ bool is_type_scalar(const type_t *type)
        assert(!is_typeref(type));
 
        switch (type->kind) {
-               case TYPE_POINTER: return true;
-               case TYPE_BUILTIN: return is_type_scalar(type->builtin.real_type);
-               default:           break;
+       case TYPE_POINTER: return true;
+       case TYPE_BUILTIN: return is_type_scalar(type->builtin.real_type);
+       default:           break;
        }
 
        return is_type_arithmetic(type);
@@ -1693,7 +1697,7 @@ static entity_t *pack_bitfield_members(il_size_t *struct_offset,
        entity_t *member;
        for (member = first; member != NULL; member = member->base.next) {
                if (member->kind != ENTITY_COMPOUND_MEMBER)
-                       break;
+                       continue;
 
                type_t *type = member->declaration.type;
                if (type->kind != TYPE_BITFIELD)
@@ -1718,8 +1722,14 @@ static entity_t *pack_bitfield_members(il_size_t *struct_offset,
                        }
                }
 
-               member->compound_member.offset     = offset;
-               member->compound_member.bit_offset = bit_offset;
+               if (byte_order_big_endian) {
+                       size_t base_size = get_type_size(base_type) * BITS_PER_BYTE;
+                       member->compound_member.offset     = offset & ~alignment_mask;
+                       member->compound_member.bit_offset = base_size - bit_offset - bit_size;
+               } else {
+                       member->compound_member.offset     = offset;
+                       member->compound_member.bit_offset = bit_offset;
+               }
 
                bit_offset += bit_size;
                offset     += bit_offset / BITS_PER_BYTE;
@@ -1731,7 +1741,6 @@ static entity_t *pack_bitfield_members(il_size_t *struct_offset,
 
        *struct_offset    = offset;
        *struct_alignment = alignment;
-
        return member;
 }