blob: ae6d2fdb8df0dbde5e42afcd975ded4f049847c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/* Test that stack protection is done on chosen functions. */
/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
/* { dg-options "-O2 -fstack-protector-strong" } */
/* This test checks the presence of __stack_chk_fail function in assembler.
* Compiler generates _stack_chk_fail_local (wrapper) calls instead for PIC.
*/
/* { dg-require-effective-target nonpic } */
class A
{
public:
A() {}
~A() {}
void method();
int state;
};
/* Frame address exposed to A::method via "this". */
int
foo1 ()
{
A a;
a.method ();
return a.state;
}
/* Possible destroying foo2's stack via &a. */
int
global_func (A& a);
/* Frame address exposed to global_func. */
int foo2 ()
{
A a;
return global_func (a);
}
/* Frame addressed exposed through return slot. */
struct B
{
/* Discourage passing this struct in registers. */
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
int method ();
B return_slot();
};
B global_func ();
void noop ();
int foo3 ()
{
return global_func ().a1;
}
int foo4 ()
{
try {
noop ();
return 0;
} catch (...) {
return global_func ().a1;
}
}
int foo5 ()
{
try {
return global_func ().a1;
} catch (...) {
return 0;
}
}
int foo6 ()
{
B b;
return b.method ();
}
int foo7 (B *p)
{
return p->return_slot ().a1;
}
/* { dg-final { scan-assembler-times "stack_chk_fail" 7 } } */
|