Bug#136659: target/9080: optimisation on sparc leads to unalligned access in memcpy
- To: 136659@bugs.debian.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, lists@lina.inka.de, nobody@gcc.gnu.org, rth@gcc.gnu.org
- Subject: Bug#136659: target/9080: optimisation on sparc leads to unalligned access in memcpy
- From: rth@gcc.gnu.org
- Date: 26 Jan 2003 10:13:38 -0000
- Message-id: <[🔎] 20030126101338.2759.qmail@sources.redhat.com>
- Reply-to: rth@gcc.gnu.org, 136659@bugs.debian.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, lists@lina.inka.de, nobody@gcc.gnu.org, rth@gcc.gnu.org, gcc-gnats@gcc.gnu.org, 136659@bugs.debian.org
Synopsis: optimisation on sparc leads to unalligned access in memcpy
Responsible-Changed-From-To: unassigned->rth
Responsible-Changed-By: rth
Responsible-Changed-When: Sun Jan 26 10:13:38 2003
Responsible-Changed-Why:
.
State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Sun Jan 26 10:13:38 2003
State-Changed-Why:
I'm fairly sure this has been discussed before, but I can't find
the reference right away. The problem is known, and I consider
the input program incorrect.
The problem is that alignof(struct iphdr) == 4, and yet the
given pointer to that structure is only 2 byte aligned. This
violates section 6.3.2.3/7, to wit:
If the resulting pointer is not correctly aligned for the
pointed-to type, the behavior is undefined.
GCC uses this clause to infer from the type of the pointer the
alignment that it *must* have.
There are two solutions for this piece of code.
One, use packed data structures, so that they are 1 byte aligned.
In this case something like
struct iphdr_u {
struct iphdr h __attribute__((packed));
};
followed by
&tmp_iphdr->h.saddr
Two, don't cast to struct iphdr at all. Instead use offsetof
to find the proper displacement into the buffer.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9080
Reply to: