PR tree-optimization/86415 - strlen() not folded for substrings within constant arrays
[official-gcc.git] / gcc / testsuite / g++.dg / fstack-protector-strong.C
blobae6d2fdb8df0dbde5e42afcd975ded4f049847c2
1 /* Test that stack protection is done on chosen functions. */
3 /* { dg-do compile { target i?86-*-* x86_64-*-* } } */
4 /* { dg-options "-O2 -fstack-protector-strong" } */
6 /* This test checks the presence of __stack_chk_fail function in assembler.
7  * Compiler generates _stack_chk_fail_local (wrapper) calls instead for PIC.
8  */
9 /* { dg-require-effective-target nonpic } */
11 class A
13 public:
14   A() {}
15   ~A() {}
16   void method();
17   int state;
20 /* Frame address exposed to A::method via "this". */
21 int
22 foo1 ()
24   A a;
25   a.method ();
26   return a.state;
29 /* Possible destroying foo2's stack via &a. */
30 int
31 global_func (A& a);
33 /* Frame address exposed to global_func. */
34 int foo2 ()
36   A a;
37   return global_func (a);
40 /* Frame addressed exposed through return slot. */
42 struct B
44   /* Discourage passing this struct in registers. */
45   int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
46   int method ();
47   B return_slot();
50 B global_func ();
51 void noop ();
53 int foo3 ()
55   return global_func ().a1;
58 int foo4 ()
60   try {
61     noop ();
62     return 0;
63   } catch (...) {
64     return global_func ().a1;
65   }
68 int foo5 ()
70   try {
71     return global_func ().a1;
72   } catch (...) {
73     return 0;
74   }
77 int foo6 ()
79   B b;
80   return b.method ();
83 int foo7 (B *p)
85   return p->return_slot ().a1;
88 /* { dg-final { scan-assembler-times "stack_chk_fail" 7 } } */