• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 __attribute__((noinline))
fct(volatile int * buffer)13 void fct(volatile int *buffer)
14 {
15   memset(buffer - 1, 0, 7 * sizeof(int));
16 }
17 
main(int argc,char ** argv)18 int main(int argc, char **argv)
19 {
20   int prebuf[7];
21   int value1 = 42;
22   int buffer[5];
23   int value2 = 42;
24   int postbuf[7];
25   fct(prebuf + 1);
26   fct(postbuf + 1);
27   fct(buffer);
28   return value1 != 42 || value2 != 42;
29 }
30