From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12567 invoked by alias); 3 Apr 2013 08:51:51 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 12314 invoked by uid 48); 3 Apr 2013 08:51:46 -0000 From: "ebotcazou at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/51628] __attribute__((packed)) is unsafe in some cases Date: Wed, 03 Apr 2013 08:51:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: ebotcazou at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 X-SW-Source: 2013-04/txt/msg00204.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51628 --- Comment #21 from Eric Botcazou 2013-04-03 08:51:44 UTC --- > One of the C frontend issues is that the type of the address of > the field of the packed struct is int *, not int attribute((aligned(1))) > *. And this is so because nothing adjusts the type of the FIELD_DECL > to be a less aligned type. That is, we have > > type size > unit size > align 32 symtab 0 alias set -1 canonical type 0x7ffff6d175e8 > precision 32 min max 0x7ffff6d1a080 2147483647> > pointer_to_this > > packed SI file t.c line 2 col 9 size > unit size > align 8 offset_align 128 > offset sizetype> constant 0> > bit offset 0x7ffff6d170a8 bitsizetype> constant 0> context 0x7ffff6e1c3f0 Foo>> This is on x86, right? If the alignment of the field cannot be guaranteed to be that of its type, then it should be made a bit-field. Maybe it's already made a bit-field on strict-alignment targets.