[Bug c/43774] option -O2 generates wrong assembly code

2010-04-18 Thread pinskia at gcc dot gnu dot org


--- Comment #6 from pinskia at gcc dot gnu dot org  2010-04-19 01:08 ---
Just a littke more: alignof (struct _x_t) is 4 therefor so is the alignof(_x_t
::data).


-- 


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



[Bug c/43774] option -O2 generates wrong assembly code

2010-04-18 Thread dirtysalt1987 at gmail dot com


--- Comment #7 from dirtysalt1987 at gmail dot com  2010-04-19 02:25 ---
(In reply to comment #6)
 Just a littke more: alignof (struct _x_t) is 4 therefor so is the alignof(_x_t
 ::data).
 
3ku very much,with your explanation I think I can understand it..3ku very much.


-- 


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



[Bug c/43774] option -O2 generates wrong assembly code

2010-04-17 Thread jakub at gcc dot gnu dot org


--- Comment #1 from jakub at gcc dot gnu dot org  2010-04-17 06:55 ---
You should make the struct packed, because otherwise you are accessing it
unaligned.


-- 


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



[Bug c/43774] option -O2 generates wrong assembly code

2010-04-17 Thread dirtysalt1987 at gmail dot com


--- Comment #2 from dirtysalt1987 at gmail dot com  2010-04-17 08:11 ---
(In reply to comment #1)
 You should make the struct packed, because otherwise you are accessing it
 unaligned.


I think the main problem coming from that GCC replace the 'strlen' function
with the following code.

.L2:
movl(%ecx), %eax //$ecx is the beginning of string..
addl$4, %ecx //seems to access the content in 4 bytes each time.
leal-16843009(%eax), %edx
notl%eax
andl%eax, %edx
andl$-2139062144, %edx
je  .L2

But it seems the piece of code can only be used when the valid memory size is
4*N,otherwise it will make a 'Invalid read'...

So under what sitaution, GCC will replace 'strlen' call with the above code. 


-- 


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



[Bug c/43774] option -O2 generates wrong assembly code

2010-04-17 Thread dirtysalt1987 at gmail dot com


--- Comment #3 from dirtysalt1987 at gmail dot com  2010-04-17 09:45 ---
(In reply to comment #1)
 You should make the struct packed, because otherwise you are accessing it
 unaligned.
 

If I recompile it with -O0, the assembly code call 'strlen' function.And I use
Valgrind to run it,there is no 'Invalid read'


-- 


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



[Bug c/43774] option -O2 generates wrong assembly code

2010-04-17 Thread schwab at linux-m68k dot org


--- Comment #4 from schwab at linux-m68k dot org  2010-04-17 09:49 ---
The compiler can assume that *x is correctly aligned, so this is not a bug.


-- 

schwab at linux-m68k dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID


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



[Bug c/43774] option -O2 generates wrong assembly code

2010-04-17 Thread dirtysalt1987 at gmail dot com


--- Comment #5 from dirtysalt1987 at gmail dot com  2010-04-17 10:28 ---
(In reply to comment #1)
 You should make the struct packed, because otherwise you are accessing it
 unaligned.
 

3ku for your reply.Your reply is much more useful than Axxx's reply.3ku very
much:).


-- 


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