(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
Wstringop-overflow-40.c
       1  /* PR c/50584 - No warning for passing small array to C99 static array
       2     declarator
       3     { dg-do compile }
       4     { dg-options "-Wall" } */
       5  
       6  typedef __INT16_TYPE__ int16_t;
       7  
       8  void fa2 (int16_t[2]);
       9  void fxa2 (int16_t[2]) __attribute__ ((nonnull));
      10  
      11  void fas2 (int16_t[static 2]);
      12  
      13  void fvla (unsigned n, int16_t[n]);
      14  
      15  void test_array_1_dim (void)
      16  {
      17    int16_t a1[1];
      18    int16_t a2[2];
      19    int16_t i;
      20  
      21    fa2 (0);
      22    fa2 (a2);
      23    fa2 (a1);                   // { dg-warning "'fa2' accessing 4 bytes in a region of size 2 " }
      24    fa2 (&i);                   // { dg-warning "'fa2' accessing 4 bytes in a region of size 2 " }
      25  
      26    fxa2 (0);                   // { dg-warning "\\\[-Wnonnull" }
      27    fxa2 (a2);
      28    fxa2 (a1);                  // { dg-warning "'fxa2' accessing 4 bytes in a region of size 2 " }
      29    fxa2 (&i);                  // { dg-warning "'fxa2' accessing 4 bytes in a region of size 2 " }
      30  
      31    fas2 (0);                   // { dg-warning "\\\[-Wnonnull" }
      32    fas2 (a2);
      33    fas2 (a1);                  // { dg-warning "'fas2' accessing 4 bytes in a region of size 2 " }
      34    fas2 (&i);                  // { dg-warning "'fas2' accessing 4 bytes in a region of size 2 " }
      35  
      36    fvla (1, 0);                // { dg-warning "\\\[-Wnonnull" }
      37    fvla (1, &i);
      38    fvla (2, a2);
      39    fvla (2, a1);               // { dg-warning "'fvla' accessing 4 bytes in a region of size 2 " }
      40    fvla (2, &i);               // { dg-warning "'fvla' accessing 4 bytes in a region of size 2 " }
      41  }
      42  
      43  
      44  void fac2 (const int16_t[2]);
      45  void fxac2 (const int16_t[2]) __attribute__ ((nonnull));
      46  
      47  void facs2 (const int16_t[static 2]);
      48  
      49  void fvlac (unsigned n, const int16_t[n]);
      50  
      51  void test_const_array_1_dim (void)
      52  {
      53    int16_t a1[1];
      54    int16_t a2[2];
      55    int16_t i;
      56  
      57    fac2 (0);
      58    fac2 (a2);
      59    fac2 (a1);                  // { dg-warning "'fac2' reading 4 bytes from a region of size 2 " }
      60    fac2 (&i);                  // { dg-warning "'fac2' reading 4 bytes from a region of size 2 " }
      61  
      62    fxac2 (0);                  // { dg-warning "\\\[-Wnonnull" }
      63    fxac2 (a2);
      64    fxac2 (a1);                 // { dg-warning "'fxac2' reading 4 bytes from a region of size 2 " }
      65    fxac2 (&i);                 // { dg-warning "'fxac2' reading 4 bytes from a region of size 2 " }
      66  
      67    facs2 (0);                  // { dg-warning "\\\[-Wnonnull" }
      68    facs2 (a2);
      69    facs2 (a1);                 // { dg-warning "'facs2' reading 4 bytes from a region of size 2 " }
      70    facs2 (&i);                 // { dg-warning "'facs2' reading 4 bytes from a region of size 2 " }
      71  
      72    fvlac (1, 0);               // { dg-warning "\\\[-Wnonnull" }
      73    fvlac (1, &i);
      74    fvlac (2, a2);
      75    fvlac (2, a1);              // { dg-warning "'fvlac' reading 4 bytes from a region of size 2 " }
      76    fvlac (2, &i);              // { dg-warning "'fvlac' reading 4 bytes from a region of size 2 " }
      77  }
      78  
      79  
      80  void fca3x5 (int16_t[3][5]);
      81  void fcas5x7 (int16_t[static 5][7]);
      82  
      83  struct Snx5 { int16_t a3x5[3][5], a2x5[2][5], a1x5[1][5]; };
      84  struct Snx7 { int16_t a5x7[5][7], a4x7[4][7], a1x7[1][7]; };
      85  struct S0x7 { int x; int16_t a0x7[0][7]; };
      86  
      87  void test_array_2_dim (struct Snx5 *px5, struct Snx7 *px7, struct S0x7 *p0x7)
      88  {
      89    int16_t a0x5[0][5], a1x5[1][5], a2x5[2][5], a3x5[3][5], a4x5[4][5];
      90  
      91    fca3x5 (a3x5);
      92    fca3x5 (a4x5);
      93    fca3x5 (a2x5);              // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 20" }
      94    fca3x5 (a1x5);              // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 10" }
      95    fca3x5 (a0x5);              // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 0" }
      96  
      97    fca3x5 (px5->a3x5);
      98    fca3x5 (px5->a2x5);         // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 20" }
      99    fca3x5 (px5->a1x5);         // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 10" "pr96346" { xfail *-*-* } }
     100  
     101    {
     102      int16_t (*pa2x5)[5] = &a2x5[0];
     103      fca3x5 (pa2x5);           // { dg-warning "'fca3x5' accessing 30 bytes in a region of size 10" }
     104      ++pa2x5;
     105      fca3x5 (pa2x5);           // { dg-warning "'fca3x5' accessing 30 bytes " }
     106    }
     107  
     108    int16_t a0x7[0][7], a1x7[1][7], a4x7[4][7], a5x7[5][7], a99x7[99][7];
     109    fcas5x7 (a99x7);
     110    fcas5x7 (a5x7);
     111    fcas5x7 (a4x7);             // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 56" }
     112    fcas5x7 (a1x7);             // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 14" }
     113    fcas5x7 (a0x7);             // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 0" }
     114  
     115    fcas5x7 (px7->a5x7);
     116    fcas5x7 (px7->a4x7);        // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 56" }
     117    fcas5x7 (px7->a1x7);        // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 14" "pr96346" { xfail *-*-* } }
     118  
     119    fcas5x7 (p0x7->a0x7);       // { dg-warning "'fcas5x7' accessing 70 bytes in a region of size 0" "pr96346" { xfail *-*-* } }
     120  }