1// Test that a stack overflow fails as expected
2
3// RUN: %clang_noscs %s -o %t -DITERATIONS=3
4// RUN: %run %t | FileCheck %s
5// RUN: %clang_noscs %s -o %t -DITERATIONS=12
6// RUN: %run %t | FileCheck -check-prefix=OVERFLOW_SUCCESS %s
7
8// RUN: %clang_scs %s -o %t -DITERATIONS=3
9// RUN: %run %t | FileCheck %s
10
11// On aarch64 we just load the return address from the shadow call stack so we
12// do not expect to see the output from print_and_exit.
13// RUN: %clang_scs %s -o %t -DITERATIONS=12
14// RUN: %run %t | FileCheck %S/overflow.c
15
16#include <stdio.h>
17#include <stdlib.h>
18
19#include "minimal_runtime.h"
20
21void print_and_exit(void) {
22// CHECK-NOT: Stack overflow successful.
23// OVERFLOW_SUCCESS: Stack overflow successful.
24 scs_fputs_stdout("Stack overflow successful.\n");
25 exit(status: 0);
26}
27
28int scs_main(void)
29{
30 void *addrs[4];
31 for (int i = 0; i < ITERATIONS; i++)
32 addrs[i] = &print_and_exit;
33
34 scs_fputs_stdout("Returning.\n");
35
36 return 0;
37}
38

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