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

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
A few more test cases:

$ cat z.c && gcc -O2 -S -Wall z.c
int idx_negative (void)
{ 
  int n = 4;
  char a[n];
  return a[-99];             // -Warray-bounds (since GCC 8)
}

int idx_cst_too_big (void)
{
  int n = 4;
  char a[n];
  return a[n + 1];           // missing _Warray-bounds
}

int idx_out_of_type_bounds (unsigned char n)
{
  char a[n];
  return a[__INT_MAX__];     // missing -Warray-bounds
}

int idx_var_too_big (int n)
{ 
  char a[n];
  return a[n + 1];           // missing -Warray-bounds
}

z.c: In function ‘idx_negative’:
z.c:5:11: warning: array subscript -99 is below array bounds of ‘char[<U4ea0> +
1]’ [-Warray-bounds]
    5 |   return a[-99];             // _Warray-bounds (since GCC 8)
      |          ~^~~~~

Reply via email to