This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
target/9080: optimisation on sparc leads to unalligned access in memcpy
- From: Matthias Klose <doko at debian dot org>
- To: gcc-gnats at gcc dot gnu dot org, debian-gcc at lists dot debian dot org
- Date: Sat, 28 Dec 2002 14:46:00 +0100
- Subject: target/9080: optimisation on sparc leads to unalligned access in memcpy
- Reply-to: 136659 at bugs dot debian dot org
>Number: 9080
>Category: target
>Synopsis: optimisation on sparc leads to unalligned access in memcpy
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Sat Dec 28 05:56:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Bernd Eckenfels <lists@lina.inka.de>
>Release: 3.2.1 (Debian) (Debian unstable)
>Organization:
The Debian Project
>Environment:
System: Debian GNU/Linux (unstable)
Architecture: sparc
host: sparc-linux
gcc version 3.2.2 20021212 (Debian prerelease)
>Description:
[ Reported to the Debian BTS as report #136659.
Please CC 136659@bugs.debian.org on replies.
Log of report can be found at http://bugs.debian.org/136659 ]
[ rechecked with gcc-3.2 CVS 20021212 ]
To add to my problem (reported on debian devel) here is a test program to
reproduce it:
Output with o=2 (unaligned)
ecki@auric:~$ ./bla
Start of struct 0xeffffc70, content: a=aaaaaaaaaaaaaa rel-pos x=12 offset
o=2
Now we are going to memcpy dst=a+x+o=0xeffffc7e
result of a+x+o access: b=aaaabbbbbbbbbb
Now we are going to bcopy dst=&(tmp_iphdr->saddr)=0xeffffc7e
result of bcopy &(tmp_iphdr->saddr) access: b=aaaabbbbbbbbbb
Now we are going to memcpy dst=&(tmp_iphdr->saddr)=0xeffffc7e
Bus error
Output with o=4 (aligned)
ecki@auric:~$ gcc -O2 -o bla bla.c
ecki@auric:~$ ./bla
Start of struct 0xeffffc70, content: a=aaaaaaaaaaaaaa rel-pos x=12 offset
o=4
Now we are going to memcpy dst=a+x+o=0xeffffc80
result of a+x+o access: b=aaaabbbbbbbbbb
Now we are going to bcopy dst=&(tmp_iphdr->saddr)=0xeffffc80
result of bcopy &(tmp_iphdr->saddr) access: b=aaaabbbbbbbbbb
Now we are going to memcpy dst=&(tmp_iphdr->saddr)=0xeffffc80
result of memcpy &(tmp_iphdr->saddr) access: b=aaaabbbbbbbbbb
Note: in both cases the pointer to the target (of bcopy and memcpy) are the
same a+x+o=0xeffffc7e and &(tmp_iphdr->saddr)=0xeffffc7e. The first case
works with memcpy, the second doesnt. This looks clearly like some broken
optimization.
Indeed:
ecki@auric:~$ gcc -O0 -o bla bla.c
ecki@auric:~$ ./bla
Start of struct 0xeffffc70, content: a=aaaaaaaaaaaaaa rel-pos x=12 offset
o=2
Now we are going to memcpy dst=a+x+o=0xeffffc7e
result of a+x+o access: b=aaaabbbbbbbbbb
Now we are going to bcopy dst=&(tmp_iphdr->saddr)=0xeffffc7e
result of bcopy &(tmp_iphdr->saddr) access: b=aaaabbbbbbbbbb
Now we are going to memcpy dst=&(tmp_iphdr->saddr)=0xeffffc7e
result of memcpy &(tmp_iphdr->saddr) access: b=aaaabbbbbbbbbb
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: