[Bug c/43009] segmentation fault with -O3 when accessing byte-aligned array as dwords

2010-02-09 Thread ajk dot xyz at gmail dot com


--- Comment #4 from ajk dot xyz at gmail dot com  2010-02-09 16:47 ---
(In reply to comment #3)
> Your pointer isn't properly aligned to be accessed via uint32_t*.
> 

And should it? If 'yes', then why GCC generates working code for that source
without optimization or with -O2 ? Or even when some debug printf(...) inserted
in the for-loop body. Strange behaviour, anyway.


-- 

ajk dot xyz at gmail dot com changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |


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



[Bug c/43009] segmentation fault with -O3 when accessing byte-aligned array as dwords

2010-02-09 Thread ajk dot xyz at gmail dot com


--- Comment #2 from ajk dot xyz at gmail dot com  2010-02-09 15:52 ---
Created an attachment (id=19829)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19829&action=view)
output for: gcc -v -save-temps -Wall -Werror -O3 2.c -o 2


-- 


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



[Bug c/43009] segmentation fault with -O3 when accessing byte-aligned array as dwords

2010-02-09 Thread ajk dot xyz at gmail dot com


--- Comment #1 from ajk dot xyz at gmail dot com  2010-02-09 15:48 ---
Created an attachment (id=19828)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19828&action=view)
the preprocessed file (*.i*) that triggers the bug


-- 


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



[Bug c/43009] New: segmentation fault with -O3 when accessing byte-aligned array as dwords

2010-02-09 Thread ajk dot xyz at gmail dot com
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)
Target: x86_64-linux-gnu

Resulting binary crushes with segmentation fault if gcc compile options include
-O3.

Source code:

#include 
#include 
#include 
#include 

void process_buf(uint32_t *buf)
{
 int i;
 uint32_t t = 0;
 for(i = 0; i < 16; i++)
  buf[i] = ++t; // segmentation fault
}

int main(int argc, char **argv)
{
 char *buf = malloc(65);
 int n;
 process_buf((uint32_t*)(buf + 1));
 n = write(1, buf + 1, 64);
 return 0;
}


-- 
   Summary: segmentation fault with -O3 when accessing byte-aligned
array as dwords
   Product: gcc
   Version: 4.4.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ajk dot xyz at gmail dot com


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