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 // The behavioral check for SCS + overflow lives in the tests overflow-x86_64.c 12 // and overflow-aarch64.c. This is because the expected behavior is different 13 // between the two platforms. On x86_64 we crash because the comparison between 14 // the shadow call stack and the regular stack fails. On aarch64 there is no 15 // comparison, we just load the return address from the shadow call stack. So we 16 // just expect not to see the output from print_and_exit. 17 18 #include <stdio.h> 19 #include <stdlib.h> 20 21 #include "minimal_runtime.h" 22 23 void print_and_exit(void) { 24 // CHECK-NOT: Stack overflow successful. 25 // OVERFLOW_SUCCESS: Stack overflow successful. 26 scs_fputs_stdout("Stack overflow successful.\n"); 27 exit(0); 28 } 29 30 int scs_main(void) 31 { 32 void *addrs[4]; 33 for (int i = 0; i < ITERATIONS; i++) 34 addrs[i] = &print_and_exit; 35 36 scs_fputs_stdout("Returning.\n"); 37 38 return 0; 39 } 40