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  const char *buf_hot;
      19  const char *buf_cold;
      20  
      21  void foo (int path);
      22  
      23  int
      24  main (int argc, char *argv[])
      25  {
      26    int i;
      27    buf_hot =  "hello";
      28    buf_cold = "world";
      29    for (i = 0; i < MAXITER; i++)
      30      foo (argc);
      31    return 0;
      32  }
      33  
      34  void NOINLINE
      35  foo (int path)
      36  {
      37  #ifdef __APPLE__
      38    static int i __attribute__ ((section ("__DATA,__data")));
      39  #else
      40    static int i __attribute__((section(".data")));
      41  #endif
      42    if (path)
      43      {
      44        for (i = 0; i < SIZE; i++)
      45  	sarr[i] = buf_hot;
      46      }
      47    else
      48      {
      49        for (i = 0; i < SIZE; i++)
      50  	sarr[i] = buf_cold;
      51      }
      52  }
      53  
      54  /* { dg-final-use-not-autofdo { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold" { target *-*-linux* *-*-gnu* } } } */
      55  /* { dg-final-use-not-autofdo { scan-assembler {.section[\t ]*__TEXT,__text_cold[^\n]*[\n\r]+_foo.cold:} { target *-*-darwin* } } } */