(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
Wstringop-overflow-69.c
       1  /* PR tree-optimization/97027 - missing warning on buffer overflow storing
       2     a larger scalar into a smaller array
       3     Verify overflow by vector stores.
       4     { dg-do compile }
       5     { dg-options "-O2 -Wno-psabi" } */
       6  
       7  #define V(N) __attribute__ ((vector_size (N)))
       8  #define C1 (VC1){ 0 }
       9  #define C2 (VC2){ 0, 1 }
      10  #define C4 (VC4){ 0, 1, 2, 3 }
      11  #define C8 (VC8){ 0, 1, 2, 3, 4, 5, 6, 7 }
      12  #define C16 (VC16){ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
      13  
      14  typedef V (1) char VC1;
      15  typedef V (2) char VC2;
      16  typedef V (4) char VC4;
      17  typedef V (8) char VC8;
      18  typedef V (16) char VC16;
      19  
      20  extern char a1[1], a2[2], a3[3], a4[4], a5[5], a6[6], a7[7], a8[8], a15[15];
      21  
      22  extern VC1 c1;
      23  extern VC2 c2;
      24  extern VC4 c4;
      25  extern VC8 c8;
      26  extern VC16 c16;
      27  
      28  extern VC1 fc1 (void);
      29  extern VC2 fc2 (void);
      30  extern VC4 fc4 (void);
      31  extern VC8 fc8 (void);
      32  extern VC16 fc16 (void);
      33  
      34  void nowarn (void)
      35  {
      36    *(VC1*)a1 = C1;
      37    *(VC2*)a2 = C2;
      38    *(VC4*)a4 = C4;
      39    *(VC4*)a5 = C4;
      40    *(VC4*)a6 = C4;
      41    *(VC4*)a7 = C4;
      42    *(VC8*)a8 = C8;
      43    *(VC8*)a15 = C8;
      44  }
      45  
      46  void warn_vec_lit (void)
      47  {
      48    *(VC2*)a1 = C2;       // { dg-warning "writing 2 bytes into a region of size 1" }
      49    *(VC4*)a2 = C4;       // { dg-warning "writing 4 bytes into a region of size 2" }
      50    *(VC4*)a3 = C4;       // { dg-warning "writing 4 bytes into a region of size 3" }
      51    *(VC8*)a4 = C8;       // { dg-warning "writing 8 bytes into a region of size 4" }
      52    *(VC8*)a7 = C8;       // { dg-warning "writing 8 bytes into a region of size 7" }
      53    *(VC16*)a15 = C16;    // { dg-warning "writing 16 bytes into a region of size 15" }
      54  }
      55  
      56  void warn_vec_decl (void)
      57  {
      58    *(VC2*)a1 = c2;       // { dg-warning "writing 2 bytes into a region of size 1" }
      59    *(VC4*)a2 = c4;       // { dg-warning "writing 4 bytes into a region of size 2" }
      60    *(VC4*)a3 = c4;       // { dg-warning "writing 4 bytes into a region of size 3" }
      61    *(VC8*)a4 = c8;       // { dg-warning "writing 8 bytes into a region of size 4" }
      62    *(VC8*)a7 = c8;       // { dg-warning "writing 8 bytes into a region of size 7" }
      63    *(VC16*)a15 = c16;    // { dg-warning "writing 16 bytes into a region of size 15" }
      64  }
      65  
      66  void warn_vec_parm (VC2 pc2, VC4 pc4, VC8 pc8, VC16 pc16)
      67  {
      68    *(VC2*)a1 = pc2;      // { dg-warning "writing 2 bytes into a region of size 1" }
      69    *(VC4*)a2 = pc4;      // { dg-warning "writing 4 bytes into a region of size 2" }
      70    *(VC4*)a3 = pc4;      // { dg-warning "writing 4 bytes into a region of size 3" }
      71    *(VC8*)a4 = pc8;      // { dg-warning "writing 8 bytes into a region of size 4" }
      72    *(VC8*)a7 = pc8;      // { dg-warning "writing 8 bytes into a region of size 7" }
      73    *(VC16*)a15 = pc16;   // { dg-warning "writing 16 bytes into a region of size 15" }
      74  }
      75  
      76  void warn_vec_func (void)
      77  {
      78    *(VC2*)a1 = fc2 ();   // { dg-warning "writing 2 bytes into a region of size 1" }
      79    *(VC4*)a2 = fc4 ();   // { dg-warning "writing 4 bytes into a region of size 2" }
      80    *(VC4*)a3 = fc4 ();   // { dg-warning "writing 4 bytes into a region of size 3" }
      81    *(VC8*)a4 = fc8 ();   // { dg-warning "writing 8 bytes into a region of size 4" }
      82    *(VC8*)a7 = fc8 ();   // { dg-warning "writing 8 bytes into a region of size 7" }
      83    *(VC16*)a15 = fc16 ();// { dg-warning "writing 16 bytes into a region of size 15" }
      84  }