Debian Codegraph @

gcc/testsuite/g++.dg/torture/harden-cfr-throw.C

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fharden-control-flow-redundancy -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */
3
4 #if ! __OPTIMIZE__ && ! defined NO_OPTIMIZE
5 /* Without optimization, functions with cleanups end up with an extra
6 resx that is not optimized out, so arrange to optimize them. */
7 void __attribute__ ((__optimize__ (1))) h2(void);
8 void __attribute__ ((__optimize__ (1))) h2b(void);
9 #endif
10
11 /* Check that we insert cleanups for checking around the bodies of
12 maybe-throwing functions. */
13
14 extern void g (void);
15 extern void g2 (void);
16
17 void f(int i) {
18 if (i)
19 g ();
20 /* Out-of-line checks here, and in the implicit handler. */
21 }
22
23 void f2(int i) {
24 if (i)
25 g ();
26 else
27 g2 ();
28 /* Out-of-line checks here, and in the implicit handler. */
29 }
30
31 void h(void) {
32 try {
33 g ();
34 } catch (...) {
35 throw;
36 }
37 /* Out-of-line checks here, and in the implicit handler. */
38 }
39
40 struct needs_cleanup {
41 ~needs_cleanup();
42 };
43
44 void h2(void) {
45 needs_cleanup y; /* No check in the cleanup handler. */
46 g();
47 /* Out-of-line checks here, and in the implicit handler. */
48 }
49
50 extern void __attribute__ ((__nothrow__)) another_cleanup (void*);
51
52 void h2b(void) {
53 int x __attribute__ ((cleanup (another_cleanup)));
54 g();
55 /* Out-of-line checks here, and in the implicit handler. */
56 }
57
58 void h3(void) {
59 try {
60 throw 1;
61 } catch (...) {
62 }
63 /* Out-of-line checks here, and in the implicit handler. */
64 }
65
66 void h4(void) {
67 throw 1;
68 /* Inline check in the cleanup around the __cxa_throw noreturn call. */
69 }
70
71 /* { dg-final { scan-tree-dump-times "hardcfr_check" 12 "hardcfr" } } */
72 /* { dg-final { scan-tree-dump-times "builtin_trap" 1 "hardcfr" } } */
73 /* { dg-final { scan-tree-dump-times "Bypassing" 0 "hardcfr" } } */