This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/69355] [5 Regression] Wrong results with -O1 optimization


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69355

--- Comment #19 from Martin Jambor <jamborm at gcc dot gnu.org> ---
Because the reduced testcase from comment #10 does not fail for me (on
revision 232662), I have tried to use creduce myself but have never
ended up with anything useful (I got source with undefined behavior
that would be passing and failing on different x86_64 machines).

So I looked at the situation and created the following C artificial
testcase that "fails" even on the current mainline.  However, it
breaks at least the aliasing rules, if not more, so I am not sure
whether we actually want it in the testcase (perhaps with
-fno-strict-aliasing as a QoI test?).

To be clear, even though this testcase is ugly, it is exactly what
actually happens in the original one.  A scalar field is type-punned
and a structure gets stored in its place and consequently the data
there are forgotten when the scalarized structure is being copied to
the result_decl.


struct S
{
  void *a;
  long double b;
};

struct Z
{
  long l;
  short s;
} __attribute__((packed));

struct S __attribute__((noclone, noinline))
foo (void *v, struct Z *z)
{
  struct S t;
  t.a = v;
  *(struct Z *) &t.b = *z;
  return t;
}

struct Z gz;

int
main (int argc, char **argv)
{
  struct S s;

  gz.l = 0xbeef;
  gz.s = 0xab;

  s = foo ((void *) 0, &gz);

  if ((((struct Z *) &s.b)->l != gz.l)
      || (((struct Z *) &s.b)->s != gz.s))
    __builtin_abort ();
  return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]