(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
uninit-suppress_3.c
       1  /* PR middle-end/98871 - Cannot silence -Wmaybe-uninitialized at declaration
       2     site
       3     { dg-do compile }
       4     { dg-options "-O1 -Wall" } */
       5  
       6  struct A
       7  {
       8    int x;
       9  };
      10  
      11  // Verify that suppression works at every inlining level.
      12  
      13  static int f0 (int *x)
      14  {
      15  #pragma GCC diagnostic push
      16  #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
      17  
      18    return ++*x;
      19  
      20  #pragma GCC diagnostic pop
      21  }
      22  
      23  static int f1 (int *p, int n)
      24  {
      25    struct A a;
      26    for (int i = 0; i < n; ++i) {
      27      if (p[i] > 1) {
      28        a = (struct A){p[i]};
      29      }
      30    }
      31  	
      32    return f0 (&a.x);
      33  }
      34  
      35  int f2 (void)
      36  {
      37    int a[] = { 1, 2, 3, 4 };
      38    return f1 (a, 4);
      39  }
      40  
      41  
      42  static int g0 (int *x)
      43  {
      44    return ++*x;
      45  }
      46  
      47  static int g1 (int *p, int n)
      48  {
      49  #pragma GCC diagnostic push
      50  #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
      51  
      52    struct A a;
      53    for (int i = 0; i < n; ++i) {
      54      if (p[i] > 1) {
      55        a = (struct A){p[i]};
      56      }
      57    }
      58  	
      59    return g0 (&a.x);
      60  
      61  #pragma GCC diagnostic pop
      62  }
      63  
      64  int g2 (void)
      65  {
      66    int a[] = { 1, 2, 3, 4, 5 };
      67    return g1 (a, 5);
      68  }
      69  
      70  
      71  static int h0 (int *x)
      72  {
      73    return ++*x;
      74  }
      75  
      76  static int h1 (int *p, int n)
      77  {
      78    struct A a;
      79    for (int i = 0; i < n; ++i) {
      80      if (p[i] > 1) {
      81        a = (struct A){p[i]};
      82      }
      83    }
      84  	
      85    return h0 (&a.x);
      86  }
      87  
      88  int h2 (void)
      89  {
      90    int a[] = { 1, 2, 3, 4, 5, 6 };
      91  
      92  #pragma GCC diagnostic push
      93  #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
      94  
      95    return h1 (a, 6);
      96  
      97  #pragma GCC diagnostic pop
      98  }