From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2803 invoked by alias); 26 Jan 2003 10:13:38 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 2760 invoked by uid 48); 26 Jan 2003 10:13:38 -0000 Date: Sun, 26 Jan 2003 10:13:00 -0000 Message-ID: <20030126101338.2759.qmail@sources.redhat.com> 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 From: rth@gcc.gnu.org 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 Subject: Re: target/9080: optimisation on sparc leads to unalligned access in memcpy X-SW-Source: 2003-01/txt/msg01475.txt.bz2 List-Id: 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