38 lines · c
1// Test that a stack overflow fails as expected2 3// RUN: %clang_noscs %s -o %t -DITERATIONS=34// RUN: %run %t | FileCheck %s5// RUN: %clang_noscs %s -o %t -DITERATIONS=126// RUN: %run %t | FileCheck -check-prefix=OVERFLOW_SUCCESS %s7 8// RUN: %clang_scs %s -o %t -DITERATIONS=39// RUN: %run %t | FileCheck %s10 11// On aarch64 we just load the return address from the shadow call stack so we12// do not expect to see the output from print_and_exit.13// RUN: %clang_scs %s -o %t -DITERATIONS=1214// RUN: %run %t | FileCheck %S/overflow.c15 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(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