(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
tree-prof/
section-attr-1.c
       1  /* Checks for a bug where a function with a section attribute would prevent
       2     all later functions from being partitioned into hot and cold blocks.  */
       3  /* { dg-require-effective-target freorder } */
       4  /* { dg-options "-O2 -fno-profile-reorder-functions -freorder-blocks-and-partition -save-temps" } */
       5  
       6  #ifdef FOR_AUTOFDO_TESTING
       7  #define MAXITER 1000000
       8  #else
       9  #define MAXITER 10000
      10  #endif
      11  
      12  #define SIZE 10000
      13  
      14  #define NOINLINE __attribute__((noinline)) __attribute__ ((noclone))
      15  
      16  const char *sarr[SIZE];
      17  const char *buf_hot;
      18  const char *buf_cold;
      19  
      20  void foo (int path);
      21  
      22  #ifdef __APPLE__
      23  __attribute__ ((section ("__TEXT,__text")))
      24  #else
      25  __attribute__((section(".text")))
      26  #endif
      27  int
      28  main (int argc, char *argv[])
      29  {
      30    int i;
      31    buf_hot =  "hello";
      32    buf_cold = "world";
      33    for (i = 0; i < MAXITER; i++)
      34      foo (argc);
      35    return 0;
      36  }
      37  
      38  
      39  void NOINLINE
      40  foo (int path)
      41  {
      42    int i;
      43    if (path)
      44      {
      45        for (i = 0; i < SIZE; i++)
      46  	sarr[i] = buf_hot;
      47      }
      48    else
      49      {
      50        for (i = 0; i < SIZE; i++)
      51  	sarr[i] = buf_cold;
      52      }
      53  }
      54  
      55  /* { dg-final-use-not-autofdo { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold" { target *-*-linux* *-*-gnu* } } } */
      56  /* { dg-final-use-not-autofdo { scan-assembler {.section[\t ]*__TEXT,__text_cold[^\n]*[\n\r]+_foo.cold:} { target *-*-darwin* } } } */