11781d105SVlad Tsyrklevich // Test that a stack overflow fails as expected 21781d105SVlad Tsyrklevich 36662e989SPeter Collingbourne // RUN: %clang_noscs %s -o %t -DITERATIONS=3 46662e989SPeter Collingbourne // RUN: %run %t | FileCheck %s 56662e989SPeter Collingbourne // RUN: %clang_noscs %s -o %t -DITERATIONS=12 66662e989SPeter Collingbourne // RUN: %run %t | FileCheck -check-prefix=OVERFLOW_SUCCESS %s 76662e989SPeter Collingbourne 86662e989SPeter Collingbourne // RUN: %clang_scs %s -o %t -DITERATIONS=3 96662e989SPeter Collingbourne // RUN: %run %t | FileCheck %s 106662e989SPeter Collingbourne 11*2e1479e2SVlad Tsyrklevich // On aarch64 we just load the return address from the shadow call stack so we 12*2e1479e2SVlad Tsyrklevich // do not expect to see the output from print_and_exit. 13*2e1479e2SVlad Tsyrklevich // RUN: %clang_scs %s -o %t -DITERATIONS=12 14*2e1479e2SVlad Tsyrklevich // RUN: %run %t | FileCheck %S/overflow.c 156662e989SPeter Collingbourne 161781d105SVlad Tsyrklevich #include <stdio.h> 171781d105SVlad Tsyrklevich #include <stdlib.h> 181781d105SVlad Tsyrklevich 191781d105SVlad Tsyrklevich #include "minimal_runtime.h" 201781d105SVlad Tsyrklevich print_and_exit(void)211781d105SVlad Tsyrklevichvoid print_and_exit(void) { 221781d105SVlad Tsyrklevich // CHECK-NOT: Stack overflow successful. 231781d105SVlad Tsyrklevich // OVERFLOW_SUCCESS: Stack overflow successful. 246662e989SPeter Collingbourne scs_fputs_stdout("Stack overflow successful.\n"); 251781d105SVlad Tsyrklevich exit(0); 261781d105SVlad Tsyrklevich } 271781d105SVlad Tsyrklevich scs_main(void)286662e989SPeter Collingbourneint scs_main(void) 291781d105SVlad Tsyrklevich { 301781d105SVlad Tsyrklevich void *addrs[4]; 316662e989SPeter Collingbourne for (int i = 0; i < ITERATIONS; i++) 321781d105SVlad Tsyrklevich addrs[i] = &print_and_exit; 331781d105SVlad Tsyrklevich 346662e989SPeter Collingbourne scs_fputs_stdout("Returning.\n"); 351781d105SVlad Tsyrklevich 361781d105SVlad Tsyrklevich return 0; 371781d105SVlad Tsyrklevich } 38