(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
const-1.c
       1  /* { dg-do compile { target { nonpic || pie_enabled } } } */
       2  /* { dg-options "-O2 -Wsuggest-attribute=const -fno-finite-loops" } */
       3  
       4  extern int extern_const(int a) __attribute__ ((const));
       5  
       6  /* Trivial.  */
       7  int
       8  foo1(int a)  /* { dg-bogus "normally" "detect const candidate" } */
       9  { /* { dg-warning "const" "detect const candidate" { target *-*-* } "8" } */ 
      10    return extern_const (a);
      11  }
      12  
      13  /* Loops known to be normally and extern const calls should be safe.  */
      14  
      15  int __attribute__ ((noinline))
      16  foo2(int n)  /* { dg-bogus "normally" "detect const candidate" } */
      17  { /* { dg-warning "const" "detect const candidate" { target *-*-* } "16" } */
      18    int ret = 0;
      19    int i;
      20    for (i=0; i<n; i++)
      21      ret+=extern_const (i);
      22    return ret;
      23  }
      24  
      25  /* No warning here; we can work it by ourselves.  */
      26  static int __attribute__ ((noinline))
      27  foo2b(int n)
      28  {
      29    int ret = 0;
      30    int i;
      31    for (i=0; i<n; i++)
      32      ret+=extern_const (i);
      33    return ret;
      34  }
      35  
      36  /* Unbounded loops are not safe.  */
      37  static int __attribute__ ((noinline))
      38  foo3(unsigned int n)  /* { dg-warning "const\[^\n\]* normally" "detect const candidate" } */
      39  {
      40    int ret = 0;
      41    unsigned int i;
      42    for (i=0; extern_const (i+n); n++)
      43      ret+=extern_const (i);
      44    return ret;
      45  }
      46  
      47  int
      48  foo4(int n) /* { dg-warning "const\[^\n\]* normally" "detect const candidate" } */
      49  {
      50    return foo3(n) + foo2b(n);
      51  } 
      52  
      53  int
      54  foo5(int n)  /* { dg-bogus "normally" "detect const candidate" } */
      55  { /* { dg-warning "const" "detect const candidate" { target *-*-* } "54" } */
      56    return foo2(n);
      57  }