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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Missing warning for array   |Missing -Warray-bounds due
                   |bounds                      |to constant folding
          Component|c                           |tree-optimization
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE
   Last reconfirmed|                            |2021-9-15
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The root cause of the missing warning is the same as that of some of the same
false negatives discussed in pr35587 and pr86691: GCC folds accesses to
elements of constant arrays with initializers very early on.  Accesses to
elements for which  no initializer has been explicitly provided (and those that
are implicitly zero) are folded to zero.  The folding is done without regard to
the index and even without optimization.  At the time the warning runs the
accesses are gone from the IL.  The simple test case below shows this effect:

$ cat z.c && gcc -O2 -S -Wall -fdump-tree-original=/dev/stdout
-fdump-tree-gimple=/dev/stdout z.c 
const int a[1] = { 1 };

int f (void)
{
  return a[1];
}

;; Function f (null)
;; enabled by -tree-original


{
  return (int) a[1];
}

int f ()
{
  int D.1982;

  D.1982 = 0;
  return D.1982;
}

*** This bug has been marked as a duplicate of bug 35587 ***

Reply via email to