(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
Warray-bounds-57.c
       1  /* PR middle-end/92323 - bogus -Warray-bounds after unrolling despite
       2     __builtin_unreachable
       3     { dg-do compile }
       4     { dg-options "-O2 -Wall" } */
       5  
       6  struct S { int a[5]; } s;
       7  
       8  void sink (void*);
       9  
      10  #pragma GCC optimize "2"
      11  
      12  void f_O2 (unsigned n, struct S *p)
      13  {
      14    for (unsigned i = 1; i < n - 1; ++i)
      15      s.a[i - 1] = p->a[i];     // { dg-bogus "\\\[-Warray-bounds" }
      16  
      17    if (n < 4 || n > 5)
      18      __builtin_unreachable ();
      19  }
      20  
      21  void g_O2 (unsigned n, struct S *p)
      22  {
      23    if (n < 4 || n > 5)
      24      __builtin_unreachable ();
      25  
      26    for (unsigned i = 1; i < n - 1; ++i)
      27      s.a[i - 1] = p->a[i];
      28  }
      29  
      30  
      31  // Also exercise -O3 with loop unrolling for good measure.
      32  
      33  #pragma GCC optimize "3"
      34  
      35  struct T { int a[6]; } t;
      36  
      37  void f_O3 (unsigned n, struct T *p)
      38  {
      39    for (unsigned i = 1; i < n - 1; ++i)
      40      t.a[i - 1] = p->a[i];     // { dg-bogus "\\\[-Warray-bounds" }
      41  
      42    if (n < 5 || n > 6)
      43      __builtin_unreachable ();
      44  }
      45  
      46  void g_O3 (unsigned n, struct T *p)
      47  {
      48    if (n < 5 || n > 6)
      49      __builtin_unreachable ();
      50  
      51    for (unsigned i = 1; i < n - 1; ++i)
      52      s.a[i - 1] = p->a[i];
      53  }