1 // RUN: %clang_noscs %s -o %t 2 // RUN: %run %t 3 | FileCheck %s 3 // RUN: %run %t 12 | FileCheck -check-prefix=OVERFLOW_SUCCESS %s 4 5 // RUN: %clang_scs %s -o %t 6 // RUN: %run %t 3 | FileCheck %s 7 // RUN: not --crash %run %t 12 8 9 // Test that a stack overflow fails as expected 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 14 #include "minimal_runtime.h" 15 16 void print_and_exit(void) { 17 // CHECK-NOT: Stack overflow successful. 18 // OVERFLOW_SUCCESS: Stack overflow successful. 19 printf("Stack overflow successful.\n"); 20 exit(0); 21 } 22 23 int main(int argc, char **argv) 24 { 25 if (argc != 2) 26 exit(1); 27 28 void *addrs[4]; 29 const int iterations = atoi(argv[1]); 30 for (int i = 0; i < iterations; i++) 31 addrs[i] = &print_and_exit; 32 33 printf("Returning.\n"); 34 35 return 0; 36 } 37