1 /* { dg-do run { target cet } } */
2 /* { dg-options "-O2 -fcf-protection -mshstk" } */
3 
4 void _exit(int status) __attribute__ ((__noreturn__));
5 
6 #ifdef __x86_64__
7 # define incssp(x) __builtin_ia32_incsspq (x)
8 # define rdssp() __builtin_ia32_rdsspq ()
9 #else
10 # define incssp(x) __builtin_ia32_incsspd (x)
11 # define rdssp() __builtin_ia32_rdsspd ()
12 #endif
13 
14 static void
15 __attribute__ ((noinline, noclone))
test(unsigned long frames)16 test (unsigned long frames)
17 {
18   unsigned long ssp;
19   ssp = rdssp ();
20   if (ssp != 0)
21     {
22       unsigned long tmp = frames;
23       while (tmp > 255)
24 	{
25 	  incssp (tmp);
26 	  tmp -= 255;
27 	}
28       incssp (tmp);
29     }
30   /* We must call _exit since shadow stack is incorrect now.  */
31   _exit (0);
32 }
33 
34 int
main()35 main ()
36 {
37   test (1);
38   return 0;
39 }
40