See code below. After type-casting, the compiler incorrectly assumes that
'a.unaligned_int' is aligned on a word boundary. On a MIPSEL system (here a
Cobalt RaQ 2) a 'sw' assembler instruction is generated to store the value in
memory, resulting in a 'Segmentation fault'. Changing the 'sw' instruction to
'swl', the problem is solved.


#include <stdint.h>

#pragma pack(1)
typedef struct  {
        int8_t  byte;
        int32_t unaligned_int;
        } test_unaligned;
#pragma pack()

int main(int argc, char *argv[]) {
        test_unaligned a;

        *((int32_t *) a.unaligned_int) = 0x123456;

        return(0);
        }

-- 
           Summary: Unaligned writes on MIPSEL systems after typecast
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: maarten at contemplated dot nl
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: mipsel-netbsd2.0
  GCC host triplet: mipsel-netbsd2.0
GCC target triplet: mipsel-netbsd2.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21387

Reply via email to