Debian Codegraph @

gcc/testsuite/gcc.target/aarch64/eh_return.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fno-inline" } */
3
4 /* With BTI enabled, this test would crash with SIGILL, Illegal instruction.
5 The 2nd argument of __builtin_eh_return is expected to be an EH handler
6 within a function, rather than a separate function.
7 The current implementation of __builtin_eh_return in AArch64 backend emits a
8 jump instead of branching with LR.
9 The prologue of the handler (i.e. continuation) starts with "bti c" (vs.
10 "bti jc") which is a landing pad type prohibiting jumps, hence the exception
11 at runtime.
12 The current behavior of __builtin_eh_return is considered correct.
13 Consequently, the default option -mbranch-protection=standard needs to be
14 overridden to remove BTI. */
15 /* { dg-additional-options "-mbranch-protection=pac-ret+leaf+gcs" { target { default_branch_protection } } } */
16
17 #include <stdlib.h>
18 #include <stdio.h>
19
20 int val, test, failed;
21
22 int main (void);
23
24 void
25 eh0 (void *p)
26 {
27 val = (int)(long)p & 7;
28 if (val)
29 abort ();
30 }
31
32 void
33 eh1 (void *p, int x)
34 {
35 void *q = __builtin_alloca (x);
36 eh0 (q);
37 __builtin_eh_return (0, p);
38 }
39
40 void
41 eh2a (int a,int b,int c,int d,int e,int f,int g,int h, void *p)
42 {
43 val = a + b + c + d + e + f + g + h + (int)(long)p & 7;
44 }
45
46 void
47 eh2 (void *p)
48 {
49 eh2a (val, val, val, val, val, val, val, val, p);
50 __builtin_eh_return (0, p);
51 }
52
53
54 void
55 continuation (void)
56 {
57 test++;
58 main ();
59 }
60
61 void
62 fail (void)
63 {
64 failed = 1;
65 printf ("failed\n");
66 continuation ();
67 }
68
69 void
70 do_test1 (void)
71 {
72 if (!val)
73 eh1 (continuation, 100);
74 fail ();
75 }
76
77 void
78 do_test2 (void)
79 {
80 if (!val)
81 eh2 (continuation);
82 fail ();
83 }
84
85 int
86 main (void)
87 {
88 if (test == 0)
89 do_test1 ();
90 if (test == 1)
91 do_test2 ();
92 if (failed || test != 2)
93 exit (1);
94 exit (0);
95 }