[Bug c/43774] option -O2 generates wrong assembly code
dirtysalt1987 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Apr 17 08:12:00 GMT 2010
------- 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
More information about the Gcc-bugs
mailing list