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

            Bug ID: 86691
           Summary: missing -Warray-bounds due to early folding of
                    out-of-bounds accesses
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC folds early on the third operand of the conditional into zero causing
-Warray-bounds not to trigger.

$ cat d.c && gcc -O2 -S -Wall -Warray-bounds=2 -fdump-tree-gimple=/dev/stdout
d.c
const char a[2][3] = { "12", "123" };

int g (int i)
{
  return i ? a[0][0] : a[7][9];
}

g (int i)
{
  int D.1902;
  int iftmp.0;

  if (i != 0) goto <D.1904>; else goto <D.1905>;
  <D.1904>:
  _1 = 49;
  iftmp.0 = (int) _1;
  goto <D.1906>;
  <D.1905>:
  _2 = 0;
  iftmp.0 = (int) _2;
  <D.1906>:
  D.1902 = iftmp.0;
  return D.1902;
}

Reply via email to