1  /* Checks for a bug where static data with a section attribute within a
       2     function would stop the function being partitioned into hot and cold
       3     blocks.  */
       4  /* { dg-require-effective-target freorder } */
       5  /* { dg-options "-O2 -fno-profile-reorder-functions -freorder-blocks-and-partition -save-temps" } */
       6  
       7  #ifdef FOR_AUTOFDO_TESTING
       8  #define MAXITER 1000000
       9  #else
      10  #define MAXITER 10000
      11  #endif
      12  
      13  #define SIZE 10000
      14  
      15  #define NOINLINE __attribute__((noinline)) __attribute__ ((noclone))
      16  
      17  const char *sarr[SIZE];
      18  #ifdef __APPLE__
      19  const char *buf_hot __attribute__ ((section ("__DATA,__data")));
      20  #else
      21  const char *buf_hot __attribute__ ((section (".data")));
      22  #endif
      23  const char *buf_cold;
      24  
      25  void foo (int path);
      26  
      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* } } } */