Debian Codegraph @

gcc/testsuite/gcc.target/loongarch/pr125049.c

raw
1 /* PR 125049: ensure stack canary and its address are not leaked. */
2 /* { dg-options "-O2 -fstack-protector-strong -ffixed-r30 -ffixed-r31" } */
3 /* { dg-do run } */
4 /* { dg-require-effective-target fstack_protector } */
5
6 extern long __stack_chk_guard;
7 register long s7 asm ("s7"), *s8 asm ("s8");
8
9 [[gnu::zero_call_used_regs ("all"), gnu::noipa]] void
10 init_test (void)
11 {
12 s7 = __stack_chk_guard;
13 s8 = &__stack_chk_guard;
14 }
15
16 [[gnu::always_inline]] static inline void
17 check_reg (void)
18 {
19 #pragma GCC unroll 30
20 for (int i = 4; i < 30; i++)
21 asm goto (
22 "beq $r%0,$s7,%l[error]\n\t"
23 "beq $r%0,$s8,%l[error]\n\t"
24 :
25 : "i" (i)
26 :
27 : error
28 );
29 return;
30 error:
31 __builtin_trap ();
32 }
33
34 [[gnu::noipa]] void
35 test (void)
36 {
37 char buf[256];
38 asm ("":"+m"(buf));
39
40 check_reg ();
41 }
42
43 int
44 main (void)
45 {
46 init_test ();
47 test ();
48
49 check_reg ();
50 }