1 /* Test that stack protection is done on chosen functions. */
3 /* { dg-do compile { target i?86-*-* x86_64-*-* rs6000-*-* s390x-*-* } } */
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.
9 /* { dg-require-effective-target nonpic } */
20 /* Function frame address escaped function call. */
37 struct ArrayStruct as
;
40 /* Function frame contains array. */
46 for (i
= 0; i
< 10; ++i
)
48 aa
.as
.array
[i
] = i
* (i
-1) + i
/ 2;
50 return aa
.as
.array
[5];
53 /* Address computation based on a function frame address. */
63 /* Address cast based on a function frame address. */
68 return goo (g0
<< 2 ? (int *)(3 * (long)(void *)(&a
)) : 0);
71 /* Address cast based on a local array. */
76 return goo ((int *)(array
+ 5));
86 /* Address computaton based on a function frame address.*/
91 return goo (&bb
.one
+ sizeof(int));
94 /* Function frame address escaped via global variable. */
104 /* Check that this covers -fstack-protector. */
109 memcpy ((void *)base
, (const void *)pg0
, 105); /* { dg-warning "writing 105 bytes into a region of size 100" } */
110 return (int)(base
[32]);
113 /* Check that this covers -fstack-protector. */
117 char* p
= __builtin_alloca (100);
118 return goo ((int *)(p
+ 50));
122 global2 (struct BB
* pbb
);
124 /* Address taken on struct. */
130 bb
.one
= global2 (&bb
);
131 for (i
= 0; i
< 10; ++i
)
133 bb
.two
= bb
.one
+ bb
.two
;
134 bb
.three
= bb
.one
+ bb
.two
+ bb
.three
;
141 /* Discourage passing this struct in registers. */
142 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
;
145 struct B
global3 (void);
149 return global3 ().a1
;
157 /* { dg-final { scan-assembler-times "stack_chk_fail" 11 } } */