Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / safestack / canary.c
blob1ceaa50656f60b614e50c0b9b906276599ec870d
1 // RUN: %clang_safestack -fno-stack-protector -D_FORTIFY_SOURCE=0 -g %s -o %t.nossp
2 // RUN: %run %t.nossp 2>&1 | FileCheck --check-prefix=NOSSP %s
4 // RUN: %clang_safestack -fstack-protector-all -D_FORTIFY_SOURCE=0 -g %s -o %t.ssp
5 // RUN: env LIBC_FATAL_STDERR_=1 not --crash %run %t.ssp 2>&1 | \
6 // RUN: FileCheck -check-prefix=SSP %s
8 // Test stack canaries on the unsafe stack.
10 // REQUIRES: stable-runtime
12 #include <assert.h>
13 #include <stdio.h>
14 #include <string.h>
16 __attribute__((noinline)) void f(unsigned *y) {
17 char x;
18 char *volatile p = &x;
19 char *volatile q = (char *)y;
20 assert(p < q);
21 assert(q - p < 1024); // sanity
22 // This has technically undefined behavior, but we know the actual layout of
23 // the unsafe stack and this should not touch anything important.
24 memset(&x, 0xab, q - p + sizeof(*y));
27 int main(int argc, char **argv)
29 unsigned y;
30 // NOSSP: main 1
31 // SSP: main 1
32 fprintf(stderr, "main 1\n");
33 f(&y);
34 // NOSSP: main 2
35 // SSP-NOT: main 2
36 fprintf(stderr, "main 2\n");
37 return 0;