(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
Wstringop-overflow-2.c
       1  /* PR tree-optimization/83508 - c-c++-common/Wrestrict.c fails since r255836
       2     Test to verify that only one of -Wrestrict and -Wstringop-overflow is
       3     issued for a problem where either would be appropriate.
       4     { dg-do compile }
       5     { dg-options "-O2 -Wrestrict -Wstringop-overflow" } */
       6  
       7  #define DIFF_MAX __PTRDIFF_MAX__
       8  
       9  typedef __PTRDIFF_TYPE__ ptrdiff_t;
      10  typedef __SIZE_TYPE__ size_t;
      11  
      12  void sink (void*);
      13  
      14  void f (ptrdiff_t i, size_t n)
      15  {
      16    if (i < DIFF_MAX - 2 || DIFF_MAX - 1 > i)
      17      i = DIFF_MAX - 2;
      18  
      19    if (n < 4 || 5 < n)
      20      n = 4;
      21  
      22    char a[8] = "012";
      23  
      24    /* The following could very well be diagnosed by -Wstringop-overflow
      25       instead but there's no way to verify that only one of the two
      26       warnings is issued and the choice of -Wrestrict simply reflects
      27       the fact that -Wrestrict runs before -Wstringop-overflow.  */
      28    __builtin_strncpy (a + i, a, n);   /* { dg-warning "\\\[-Wrestrict]" } */
      29    sink (a);
      30  }