public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113630] New: -fno-strict-aliasing introduces out-of-bounds memory access
@ 2024-01-27 17:34 kristerw at gcc dot gnu.org
  2024-01-27 17:42 ` [Bug tree-optimization/113630] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: kristerw at gcc dot gnu.org @ 2024-01-27 17:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113630
           Summary: -fno-strict-aliasing introduces out-of-bounds memory
                    access
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristerw at gcc dot gnu.org
  Target Milestone: ---

The test gcc.dg/torture/pr110799.c crashes because of an out of bounds memory
access when compiled with "-O2 -fno-strict-aliasing".

What is happening is that the pre pass has changed

struct S {
    int a;
};
struct M {
    int a, b;
};

__attribute__((noipa, noinline, noclone, no_icf))
int f (struct S * p, int c, int d)
{
  int r;

  <bb 2>:
  if (c_2(D) != 0)
    goto <bb 3>;
  else
    goto <bb 6>;

  <bb 3>:
  if (d_6(D) != 0)
    goto <bb 4>;
  else
    goto <bb 5>;

  <bb 4>
  r_8 = p_4(D)->a;
  goto <bb 7>;

  <bb 5>
  r_7 = MEM[(struct M *)p_4(D)].a;
  goto <bb 7>;

  <bb 6>
  r_5 = MEM[(struct M *)p_4(D)].b;

  <bb 7>
  # r_1 = PHI <r_7(5), r_5(6), r_8(4)>
  return r_1;
}


by combining  bb 4 and bb 5 and doing all accesses as struct M:


__attribute__((noipa, noinline, noclone, no_icf))
int f (struct S * p, int c, int d)
{
  int r;
  int pretmp_9;

  <bb 2>:
  if (c_2(D) != 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 3>:
  pretmp_9 = MEM[(struct M *)p_4(D)].a;
  goto <bb 5>;

  <bb 4>:
  r_5 = MEM[(struct M *)p_4(D)].b;

  <bb 5>:
  # r_1 = PHI <pretmp_9(3), r_5(4)>
  return r_1;
}


This in turn allows later passes to hoist the two loads


__attribute__((noipa, noinline, noclone, no_icf))
int f (struct S * p, int c, int d)
{
  int r;
  int pretmp_9;

  <bb 2>:
  pretmp_9 = MEM[(struct M *)p_4(D)].a;
  r_5 = MEM[(struct M *)p_4(D)].b;
  if (c_2(D) != 0)
    goto <bb 3>;
  else
    goto <bb 4>;

  <bb 3>:

  <bb 4>:
  # r_1 = PHI <pretmp_9(3), r_5(2)>
  return r_1;
}


which now reads out of bounds when we pass a struct S as f(&s, 1, 1).

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

end of thread, other threads:[~2024-05-06 13:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-27 17:34 [Bug tree-optimization/113630] New: -fno-strict-aliasing introduces out-of-bounds memory access kristerw at gcc dot gnu.org
2024-01-27 17:42 ` [Bug tree-optimization/113630] " pinskia at gcc dot gnu.org
2024-01-27 23:34 ` [Bug tree-optimization/113630] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-01-27 23:42 ` pinskia at gcc dot gnu.org
2024-01-28  0:11 ` pinskia at gcc dot gnu.org
2024-01-29  8:04 ` rguenth at gcc dot gnu.org
2024-01-29  8:11 ` rguenth at gcc dot gnu.org
2024-01-31 11:35 ` cvs-commit at gcc dot gnu.org
2024-01-31 11:35 ` [Bug tree-optimization/113630] [11/12/13 " rguenth at gcc dot gnu.org
2024-05-06 13:15 ` cvs-commit at gcc dot gnu.org
2024-05-06 13:18 ` [Bug tree-optimization/113630] [11/12 " rguenth at gcc dot gnu.org

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).