1// RUN: %clang_safestack %s -o %t
2// RUN: %run %t
3
4// RUN: %clang_nosafestack -fno-stack-protector %s -o %t
5// RUN: not %run %t
6
7// Test that buffer overflows on the unsafe stack do not affect variables on the
8// safe stack.
9
10// REQUIRES: stable-runtime
11
12extern void *memset(void *, int, __typeof__(sizeof(0)));
13
14__attribute__((noinline))
15void fct(volatile int *buffer)
16{
17 memset(buffer - 1, 0, 7 * sizeof(int));
18}
19
20int main(int argc, char **argv)
21{
22 int prebuf[7];
23 int value1 = 42;
24 int buffer[5];
25 int value2 = 42;
26 int postbuf[7];
27 fct(buffer: prebuf + 1);
28 fct(buffer: postbuf + 1);
29 fct(buffer);
30 return value1 != 42 || value2 != 42;
31}
32

source code of compiler-rt/test/safestack/overflow.c