From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2193 invoked by alias); 18 Apr 2013 08:05:05 -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 2152 invoked by uid 48); 18 Apr 2013 08:05:03 -0000 From: "joey.ye at arm dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/56997] New: Incorrect write to packed field when strict-volatile-bitfields enabled on aarch32 Date: Thu, 18 Apr 2013 08:05:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: joey.ye at arm dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: 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/msg01660.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56997 Bug #: 56997 Summary: Incorrect write to packed field when strict-volatile-bitfields enabled on aarch32 Classification: Unclassified Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassigned@gcc.gnu.org ReportedBy: joey.ye@arm.com Target: arm/aarch32 Attached case fails when Target: all arm aarch32 Optimization level:all optimization levels. Version: Trunk 197955, 4.7, 4.6 But it passes: - if -fno-strict-volatile-bitfields is specified, or - on x86 even if -fstrict-volatile-bitfields is specified For example: arm-none-eabi-gcc -mthumb -mcpu=cortex-m0 -Os a.c -o a.s -S foo: ldr r3, .L2 lsl r2, r0, #8 ; First byte of input r0 is truncated ldr r0, [r3] uxtb r0, r0 orr r0, r2 str r0, [r3] bx lr Runtime output: Write FAIL 0x20304 --------------------- #include #include #include #ifdef SHORT #define test_type unsigned short #define MAGIC 0x102u #else #define test_type unsigned int #define MAGIC 0x1020304u #endif typedef struct s{ unsigned char Prefix; test_type Type; }__attribute((__packed__)) ss; volatile ss v; ss g; void __attribute__((noinline)) foo (test_type u) { v.Type = u; } test_type __attribute__((noinline)) bar (void) { return v.Type; } int main() { test_type temp; int err = 0; foo(MAGIC); memcpy(&g, (void *)&v, sizeof(g)); if (g.Type != MAGIC) { printf("Write FAIL 0x%x\n", g.Type); err ++; } g.Type = MAGIC; memcpy((void *)&v, &g, sizeof(v)); temp = bar(); if (temp != MAGIC) { printf("Read FAIL 0x%x\n", temp); err ++; } return err; }