(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
Wrestrict-6.c
       1  /* PR tree-optimization/83640 - ice in generic_overlap, at
       2     gimple-ssa-warn-restrict.c:814
       3     Test to verify that a pointer offset range whose upper bound is less
       4     than its lower bound (when interpreted as a signed integer) is handled
       5     correctly.
       6     { dg-do compile }
       7     { dg-options "-O2 -Wrestrict" }  */
       8  
       9  #include "range.h"
      10  
      11  extern char* strcpy (char*, const char*);
      12  extern char* stpcpy (char*, const char*);
      13  
      14  void sink (void*);
      15  
      16  void warn_2_smax_p2 (void)
      17  {
      18    char a[7] = "01234";
      19  
      20    char *d = a;
      21  
      22    ptrdiff_t i = UR (2, DIFF_MAX + (size_t)2);
      23  
      24    strcpy (d, d + i);          /* { dg-warning "accessing between 1 and 4 bytes at offsets 0 and \\\[2, 7] may overlap up to 2 bytes at offset \\\[2, 3]" } */
      25  
      26    sink (d);
      27  }
      28  
      29  void nowarn_3_smax_p2 (void)
      30  {
      31    char a[7] = "12345";
      32  
      33    char *d = a;
      34  
      35    ptrdiff_t i = UR (3, DIFF_MAX + (size_t)2);
      36  
      37    strcpy (d, d + i);
      38  
      39    sink (d);
      40  }
      41  
      42  void warn_2u_smax_p2 (void)
      43  {
      44    char a[7] = "23456";
      45  
      46    char *d = a;
      47  
      48    size_t i = UR (2, DIFF_MAX + (size_t)2);
      49  
      50    strcpy (d, d + i);          /* { dg-warning "accessing between 1 and 4 bytes at offsets 0 and \\\[2, 7] may overlap up to 2 bytes at offset \\\[2, 3]" } */
      51  
      52    sink (d);
      53  }
      54  
      55  void nowarn_3u_smax_p2 (void)
      56  {
      57    char a[7] = "34567";
      58  
      59    char *d = a;
      60  
      61    size_t i = UR (3, DIFF_MAX + (size_t)2);
      62  
      63    strcpy (d, d + i);
      64  
      65    sink (d);
      66  }