c++: prvalue of array type [PR111286]
[official-gcc.git] / gcc / testsuite / c-c++-common / torture / strub-run3.c
blobe5047a988f5bf1b835125795f613d15c6f0726e1
1 /* { dg-do run } */
2 /* { dg-options "-fstrub=strict" } */
3 /* { dg-require-effective-target alloca } */
4 /* { dg-require-effective-target strub } */
6 /* Check that a non-strub function leaves a string behind in the stack, and that
7 equivalent strub functions don't. */
9 const char test_string[] = "\x55\xde\xad\xbe\xef\xc0\x1d\xca\xfe\x55\xaa";
11 static inline __attribute__ ((__always_inline__, __strub__ ("callable")))
12 char *
13 leak_string (void)
15 int len = sizeof (test_string);
16 char *s = (char *) __builtin_alloca (len);
17 __builtin_strcpy (s, test_string);
18 asm ("" : "+m" (s));
19 return (char *) __builtin_stack_address ();
22 static inline __attribute__ ((__always_inline__))
23 int
24 look_for_string (char *e)
26 char *p = (char *) __builtin_stack_address ();
28 if (p == e)
29 __builtin_abort ();
31 if (p > e)
33 char *q = p;
34 p = e;
35 e = q;
38 for (char *re = e - sizeof (test_string); p < re; p++)
39 for (int i = 0; p[i] == test_string[i]; i++)
40 if (i == sizeof (test_string) - 1)
41 return i;
43 return 0;
46 static __attribute__ ((__noinline__, __noclone__))
47 char *
48 callable ()
50 return leak_string ();
53 static __attribute__ ((__strub__ ("at-calls")))
54 char *
55 at_calls ()
57 return leak_string ();
60 static __attribute__ ((__strub__ ("internal")))
61 char *
62 internal ()
64 return leak_string ();
67 int main ()
69 /* Since these test check stack contents above the top of the stack, an
70 unexpected asynchronous signal or interrupt might overwrite the bits we
71 expect to find and cause spurious fails. Tolerate one such overall
72 spurious fail by retrying. */
73 int i = 1;
74 while (!look_for_string (callable ()))
75 if (!i--) __builtin_abort ();
76 while (look_for_string (at_calls ()))
77 if (!i--) __builtin_abort ();
78 while (look_for_string (internal ()))
79 if (!i--) __builtin_abort ();
80 __builtin_exit (0);