public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/56997] New: Incorrect write to packed field when strict-volatile-bitfields enabled on aarch32
@ 2013-04-18  8:05 joey.ye at arm dot com
  2013-04-18  8:12 ` [Bug target/56997] " joey.ye at arm dot com
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: joey.ye at arm dot com @ 2013-04-18  8:05 UTC (permalink / raw)
  To: gcc-bugs


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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#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;
}


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2015-04-04 15:28 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-18  8:05 [Bug target/56997] New: Incorrect write to packed field when strict-volatile-bitfields enabled on aarch32 joey.ye at arm dot com
2013-04-18  8:12 ` [Bug target/56997] " joey.ye at arm dot com
2013-04-18  8:26 ` rguenth at gcc dot gnu.org
2013-04-18  8:46 ` joey.ye at arm dot com
2013-06-08 19:59 ` sandra at codesourcery dot com
2013-06-14  3:01 ` sandra at codesourcery dot com
2013-06-23 18:02 ` bernd.edlinger at hotmail dot de
2013-06-23 22:03 ` bernd.edlinger at hotmail dot de
2013-06-24  0:03 ` sandra at codesourcery dot com
2013-06-24 20:27 ` bernd.edlinger at hotmail dot de
2013-06-25 11:35 ` bernd.edlinger at hotmail dot de
2013-08-28 20:43 ` ramana at gcc dot gnu.org
2013-10-07 15:42 ` sandra at codesourcery dot com
2013-12-11 16:50 ` edlinger at gcc dot gnu.org
2013-12-11 16:59 ` edlinger at gcc dot gnu.org
2014-01-07 10:12 ` joey.ye at arm dot com
2014-02-27  7:28 ` jye2 at gcc dot gnu.org
2014-08-15  4:46 ` pinskia at gcc dot gnu.org
2014-08-15 16:36 ` bernd.edlinger at hotmail dot de
2015-04-04 15:28 ` bernd.edlinger at hotmail dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).