(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
Wstringop-overflow-8.c
       1  /* PR tree-optimization/79220 - missing -Wstringop-overflow= on a memcpy
       2     overflow with a small power-of-2 size
       3     { dg-do compile }
       4     { dg-options "-O2 -Wno-array-bounds -Wstringop-overflow" } */
       5  
       6  extern void* memcpy (void*, const void*, __SIZE_TYPE__);
       7  extern void* memmove (void*, const void*, __SIZE_TYPE__);
       8  extern void* memset (void*, int, __SIZE_TYPE__);
       9  
      10  char d[1];
      11  
      12  void test_memcpy_lit_2 (void)
      13  {
      14    memcpy (d, "01", 2);          /* { dg-warning "\\\[-Wstringop-overflow" } */
      15  }
      16  
      17  void test_memcpy_lit_4 (void)
      18  {
      19    memcpy (d, "0123", 4);        /* { dg-warning "\\\[-Wstringop-overflow" } */
      20  }
      21  
      22  void test_memmove_lit_8 (void)
      23  {
      24    memmove (d, "01234567", 8);   /* { dg-warning "\\\[-Wstringop-overflow" } */
      25  }
      26  
      27  
      28  void test_memcpy_ptr_2 (const void *s)
      29  {
      30    memcpy (d, s, 2);             /* { dg-warning "\\\[-Wstringop-overflow" } */
      31  }
      32  
      33  void test_memcpy_ptr_4 (const void *s)
      34  {
      35    memcpy (d, s, 4);             /* { dg-warning "\\\[-Wstringop-overflow" } */
      36  }
      37  
      38  void test_memcpy_ptr_8 (const void *s)
      39  {
      40    memcpy (d, s, 8);             /* { dg-warning "\\\[-Wstringop-overflow" } */
      41  }
      42  
      43  
      44  void test_memmove_ptr (const void *s)
      45  {
      46    memmove (d, s, 8);            /* { dg-warning "\\\[-Wstringop-overflow" } */
      47  }
      48  
      49  void test_memset_2 (void)
      50  {
      51    memset (d, 0, 2);             /* { dg-warning "\\\[-Wstringop-overflow" } */
      52  }
      53  
      54  void test_memset_4 (void)
      55  {
      56    memset (d, 0, 4);             /* { dg-warning "\\\[-Wstringop-overflow" } */
      57  }
      58  
      59  void test_memset_8 (void)
      60  {
      61    memset (d, 0, 8);             /* { dg-warning "\\\[-Wstringop-overflow" } */
      62  }