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

            Bug ID: 128823
           Summary: gcc.c-torture/execute/20000603-1.c aborts when f is
                    not inlined early (IPA-CP and IPA-SRA)
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bernie at codewiz dot org
  Target Milestone: ---

Created attachment 66205
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66205&action=edit
testcase

gcc.c-torture/execute/20000603-1.c aborts whenever f() reaches the IPA
passes without having been inlined early.

Reduced testcase (also attached):

struct s1 { double d; };
struct s2 { double d; };
union u { struct s1 x; struct s2 y; };

static __attribute__((noinline)) double f(struct s1 *a, struct s2 *b)
{
  a->d = 1.0;
  return b->d + 1.0;
}

int main()
{
  union u a;
  a.x.d = 0.0;
  if (f (&a.x, &a.y) != 2.0)
    __builtin_abort ();
  return 0;
}

With gcc 16.2.1 on x86_64, gcc -O2 t.c && ./a.out aborts, and main
compiles to a bare call to abort. It passes at -O1, with
-fno-strict-aliasing, or with both -fno-ipa-cp and -fno-ipa-sra. Either
pass alone is enough to break it:

- IPA-CP propagates the known aggregate value b->d == 0.0 from the call
  site, because the store through a (a struct s1) is assumed not to
  clobber the load through b (a struct s2).

- IPA-SRA turns b into a by-value double loaded in main before the
  call, on the same assumption.

The unmodified test also aborts with -O2 -flto -fno-early-inlining on
x86_64: under LTO f becomes local, and the IPA passes then change it.
Without -flto, f stays global and they leave it alone.

How we hit it: on m68k-amigaos, -fbaserel left flag_shlib set (an
out-of-tree port bug, since fixed), so f looked interposable and was never
inlined
early. With -O2 -flto -fuse-linker-plugin the linker resolution makes f
prevailing_def_ironly, and the test aborts. Other targets inline f
early, so the torture run never exercises the IPA path.

The test's comment cites DR#236 and says there is consensus that the
union makes it conforming. But the committee response to DR#236 says its
Example 2, the same shape with int/double members, is undefined, and
that "the translator has every right to rearrange accesses to *qi and
*qd by the usual aliasing rules". If so, the IPA passes are within their
rights and the test only passes by accident of early inlining.

Should it be marked noipa/noinline (and then xfailed or dropped),
or are the IPA passes expected to be as conservative here as the rest
of the pipeline?

Reply via email to