From ea2b756666fa60b47efe16510d81c3b29beab4df Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Sun, 6 Nov 2016 11:46:40 +0100 Subject: Check for stack overflow in a tested program Check if a state reaches the maximum number of stack frames allowed. To be performant, the number of stack frames are checked. In comparison, native execution checks the size of the stack. Still, this is good enough to find possible stack overflows. The limit can be changed with `-max-stack-frames`. The current default is 8192 frames. --- test/Feature/StackOverflow.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/Feature/StackOverflow.c (limited to 'test') diff --git a/test/Feature/StackOverflow.c b/test/Feature/StackOverflow.c new file mode 100644 index 00000000..837d3db8 --- /dev/null +++ b/test/Feature/StackOverflow.c @@ -0,0 +1,16 @@ +// RUN: %llvmgcc -emit-llvm -g -c -o %t.bc %s +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out %t.bc > %t.output.log 2>&1 +// RUN: FileCheck -input-file=%t.output.log %s + +void recursive(unsigned nr){ + if (nr == 0) + return; + recursive(nr-1); +} + +int main() { + recursive(10000); + return 0; +} +// CHECK: Maximum stack size reached -- cgit 1.4.1