[Bug target/21387] Unaligned writes on MIPSEL systems after typecast
--- Additional Comments From maarten at contemplated dot nl 2005-05-05 11:56 --- (In reply to comment #2) Reading your reply further, I understand that the behavior I observere is correct and related to the fact that the 'int32_t' type is assumed to be aligned. It is not a bug then, but merely a bit of a problem for me. Is there a typecast to tell the compiler that the adress references an unaligned integer, i.e. something like int32_unaligned_t? -- What|Removed |Added Status|WAITING |SUSPENDED http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21387
[Bug target/21387] Unaligned writes on MIPSEL systems after typecast
--- Additional Comments From maarten at contemplated dot nl 2005-05-05 11:49 --- (In reply to comment #2) You are completely right, the code above merely demonstrates what happens when one writes to an illegal address. The correct version, *((int32_t *) &a.unaligned_int32) = 0x123456; does work. Sorry, result of 'compressing' the problem. My 'unaligned write' problem is, however, still there. I stumbled over it when trying to compile code where copying of 16 bytes (in a char array) was implemented as two reads and writes of int64_t. The problem occurs when typecasting char arrays to integer types, see modified example: 1: #include int main(int argc, char *argv[]) { char x[100]; *((int32_t *) ((char *) (x))) = 0x123456; // ok *((int32_t *) ((char *) (x+4))) = 0x123456; // ok *((int32_t *) ((char *) (x+1))) = 0x123456; // fails return(0); } 2: (more related to original) #include #pragma pack(1) typedef struct { int8_t byte; // removing this byte, code executes char unaligned_int32[4]; } test_unaligned; #pragma pack() int main(int argc, char *argv[]) { test_unaligned a; *((int32_t *) a.unaligned_int32) = 0x123456;// fails return(0); } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21387
[Bug c++/21387] New: Unaligned writes on MIPSEL systems after typecast
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 #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