PR tree-optimization/81303
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-prof / section-attr-2.c
blob898a395cd7ebfb70d667920f671edaea490eac88
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" } */
7 #define SIZE 10000
9 #define NOINLINE __attribute__((noinline)) __attribute__ ((noclone))
11 const char *sarr[SIZE];
12 const char *buf_hot;
13 const char *buf_cold;
15 void foo (int path);
17 int
18 main (int argc, char *argv[])
20 int i;
21 buf_hot = "hello";
22 buf_cold = "world";
23 for (i = 0; i < 1000000; i++)
24 foo (argc);
25 return 0;
28 void NOINLINE
29 foo (int path)
31 static int i __attribute__((section(".data")));
32 if (path)
34 for (i = 0; i < SIZE; i++)
35 sarr[i] = buf_hot;
37 else
39 for (i = 0; i < SIZE; i++)
40 sarr[i] = buf_cold;
44 /* { dg-final-use { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold\.0" { target *-*-linux* *-*-gnu* } } } */