(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
nonnull-4.c
       1  /* PR c/78673 - sprintf missing attribute nonnull on destination argument
       2     Test to verify that calls to user-defined functions declared with
       3     the "nonnull" function attribute are diagnosed.  */
       4  /* { dg-do compile } */
       5  /* { dg-options "-O2 -Wnonnull" } */
       6  
       7  #define N(...) __attribute__ ((nonnull (__VA_ARGS__)))
       8  
       9  void N (1) f1_1 (void*);
      10  
      11  void N (1)       f2_1 (void*, void*);
      12  void N (1) N (2) f2_1_2 (void*, void*);
      13  
      14  void N (1) N (3) f3_1_3 (void*, void*, void*);
      15  
      16  void N (1, 2) N (4) g4_1_2_4 (void*, void*, void*, void*);
      17  void N (1, 3) N (4) g4_1_3_4 (void*, void*, void*, void*);
      18  void N (2, 3, 4)    g4_2_3_4 (void*, void*, void*, void*);
      19  
      20  void N () g4_all (void*, void*, void*, void*);
      21  
      22  void N (1, 3, 5, 7, 11, 13)
      23  g16_1_3_5_7_11_13 (void*, void*, void*, void*,
      24  		   void*, void*, void*, void*,
      25  		   void*, void*, void*, void*,
      26  		   void*, void*, void*, void*);
      27  
      28  static void* null (void) { return 0; }
      29  
      30  void test (void)
      31  {
      32    void *p0 = null ();
      33    void *px = &px;
      34  
      35    f1_1 (p0);   /* { dg-warning "argument 1 null where non-null expected " } */
      36    f1_1 (px);
      37  
      38    f2_1 (p0, px);  /* { dg-warning "argument 1 null" } */
      39    f2_1 (px, p0);
      40    f2_1 (p0, p0);  /* { dg-warning "argument 1 null" } */
      41  
      42    f2_1_2 (p0, px);  /* { dg-warning "argument 1 null" } */
      43    f2_1_2 (px, p0);  /* { dg-warning "argument 2 null" } */
      44    f2_1_2 (p0, p0);  /* { dg-warning "argument 1 null" } */
      45    /* { dg-warning "argument 2 null" "argument 2" { target *-*-* } .-1 } */
      46  
      47    f3_1_3 (p0, px, px);  /* { dg-warning "argument 1 null" } */
      48    f3_1_3 (px, p0, px);
      49    f3_1_3 (px, px, p0);  /* { dg-warning "argument 3 null" } */
      50    f3_1_3 (p0, p0, px);  /* { dg-warning "argument 1 null" } */
      51    f3_1_3 (px, p0, p0);  /* { dg-warning "argument 3 null" } */
      52    f3_1_3 (p0, p0, p0);  /* { dg-warning "argument 1 null" } */
      53    /* { dg-warning "argument 3 null" "argument 3" { target *-*-* } .-1 } */
      54  
      55    g4_1_2_4 (p0, px, px, px);  /* { dg-warning "argument 1 null" } */
      56    g4_1_2_4 (px, p0, px, px);  /* { dg-warning "argument 2 null" } */
      57    g4_1_2_4 (px, px, p0, px);
      58    g4_1_2_4 (px, px, px, p0);  /* { dg-warning "argument 4 null" } */
      59  
      60    g4_1_3_4 (p0, px, px, px);  /* { dg-warning "argument 1 null" } */
      61    g4_1_3_4 (px, p0, px, px);
      62    g4_1_3_4 (px, px, p0, px);  /* { dg-warning "argument 3 null" } */
      63    g4_1_3_4 (px, px, px, p0);  /* { dg-warning "argument 4 null" } */
      64  
      65    g4_2_3_4 (p0, px, px, px);
      66    g4_2_3_4 (px, p0, px, px);  /* { dg-warning "argument 2 null" } */
      67    g4_2_3_4 (px, px, p0, px);  /* { dg-warning "argument 3 null" } */
      68    g4_2_3_4 (px, px, px, p0);  /* { dg-warning "argument 4 null" } */
      69  
      70    g4_all (p0, px, px, px);  /* { dg-warning "argument 1 null" } */
      71    g4_all (px, p0, px, px);  /* { dg-warning "argument 2 null" } */
      72    g4_all (px, px, p0, px);  /* { dg-warning "argument 3 null" } */
      73    g4_all (px, px, px, p0);  /* { dg-warning "argument 4 null" } */
      74  
      75    g16_1_3_5_7_11_13 (px, px, px, px, px, px, px, px,
      76  		     px, px, px, px, px, px, px, px);
      77  
      78    g16_1_3_5_7_11_13 (px, p0, px, p0, px, p0, px, p0, p0, p0, px, p0, p0, p0, p0, p0);   /* { dg-warning "argument 13 null" } */
      79  }