2 /* { dg-options "-fstrub=all" } */
3 /* { dg-require-effective-target alloca } */
4 /* { dg-require-effective-target strub } */
6 /* Check that multi-level, multi-inlined functions still get cleaned up as
7 expected, without overwriting temporary stack allocations while they should
10 #ifndef ATTR_STRUB_AT_CALLS
11 # define ATTR_STRUB_AT_CALLS /* Defined in strub-run4d.c. */
14 const char test_string
[] = "\x55\xde\xad\xbe\xef\xc0\x1d\xca\xfe\x55\xaa";
16 static inline __attribute__ ((__always_inline__
))
20 int __attribute__ ((__strub__
)) len
= 512;
21 asm ("" : "+r" (len
));
23 __builtin_strcpy (s
, test_string
);
24 __builtin_strcpy (s
+ len
- sizeof (test_string
), test_string
);
26 return (char *) __builtin_stack_address ();
29 static inline __attribute__ ((__always_inline__
))
31 look_for_string (char *e
)
33 char *p
= (char *) __builtin_stack_address ();
45 for (char *re
= e
- sizeof (test_string
); p
< re
; p
++)
46 for (int i
= 0; p
[i
] == test_string
[i
]; i
++)
47 if (i
== sizeof (test_string
) - 1)
53 static inline ATTR_STRUB_AT_CALLS
57 int __attribute__ ((__strub__
)) len
= 512;
58 asm ("" : "+r" (len
));
60 __builtin_strcpy (s
, test_string
);
61 __builtin_strcpy (s
+ len
- sizeof (test_string
), test_string
);
63 char *ret
= leak_string ();
64 if (__builtin_strcmp (s
, test_string
) != 0)
66 if (__builtin_strcmp (s
+ len
- sizeof (test_string
), test_string
) != 0)
71 static inline ATTR_STRUB_AT_CALLS
75 int __attribute__ ((__strub__
)) len
= 512;
76 asm ("" : "+r" (len
));
78 __builtin_strcpy (s
, test_string
);
79 __builtin_strcpy (s
+ len
- sizeof (test_string
), test_string
);
81 char *ret
= innermost ();
82 if (__builtin_strcmp (s
, test_string
) != 0)
84 if (__builtin_strcmp (s
+ len
- sizeof (test_string
), test_string
) != 0)
89 static inline __attribute__ ((__strub__ ("internal")))
93 return intermediate ();
96 int __attribute__ ((__strub__ ("disabled")))
99 /* Since these test check stack contents above the top of the stack, an
100 unexpected asynchronous signal or interrupt might overwrite the bits we
101 expect to find and cause spurious fails. Tolerate one such overall
102 spurious fail by retrying. */
104 while (look_for_string (internal ()))
105 if (!i
--) __builtin_abort ();