diff options
Diffstat (limited to 'test/Feature')
-rw-r--r-- | test/Feature/RewriteEqualities.c | 38 | ||||
-rw-r--r-- | test/Feature/arithmetic-right-overshift-sym-conc.c | 25 |
2 files changed, 55 insertions, 8 deletions
diff --git a/test/Feature/RewriteEqualities.c b/test/Feature/RewriteEqualities.c new file mode 100644 index 00000000..3cb9c5fe --- /dev/null +++ b/test/Feature/RewriteEqualities.c @@ -0,0 +1,38 @@ +// RUN: %llvmgcc %s -emit-llvm -O0 -c -o %t.bc +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out --search=dfs --write-pcs --rewrite-equalities=false %t.bc +// RUN: grep "N0:(Read w8 2 x)" %t.klee-out/test000003.pc +// RUN: grep "N0)" %t.klee-out/test000003.pc +// RUN: rm -rf %t.klee-out +// RUN: %klee --output-dir=%t.klee-out --search=dfs --write-pcs --rewrite-equalities %t.bc +// RUN: grep "(Read w8 8 const_arr1)" %t.klee-out/test000003.pc + +#include <stdio.h> +#include <klee/klee.h> + +int run(unsigned char * x, unsigned char * y) { + y[6] = 15; + + if(x[2] >= 10){ + return 1; + } + + if(y[x[2]] < 11){ + if(x[2] == 8){ + return 2; + } else{ + return 3; + } + } else{ + return 4; + } +} + +unsigned char y[255]; + +int main() { + unsigned char x[4]; + klee_make_symbolic(&x, sizeof x, "x"); + + return run(x, y); +} diff --git a/test/Feature/arithmetic-right-overshift-sym-conc.c b/test/Feature/arithmetic-right-overshift-sym-conc.c index a771bc75..7af6f9d7 100644 --- a/test/Feature/arithmetic-right-overshift-sym-conc.c +++ b/test/Feature/arithmetic-right-overshift-sym-conc.c @@ -15,11 +15,13 @@ typedef enum // We're using signed ints so should be doing // arithmetic right shift. -int overshift(volatile unsigned int y, const char * type) +// lhs should be a constant +int overshift(signed int lhs, volatile unsigned int y, const char * type) { overshift_t ret; - volatile signed int x=15; + volatile signed int x = lhs; unsigned int limit = sizeof(x)*8; + assert(!klee_is_symbolic(x)); volatile signed int result; result = x >> y; // Potential overshift @@ -45,10 +47,13 @@ int overshift(volatile unsigned int y, const char * type) int main(int argc, char** argv) { - // Concrete overshift volatile unsigned int y = sizeof(unsigned int)*8; - overshift_t conc = overshift(y, "Concrete"); - assert( conc == TO_ZERO); + // Try with +ve lhs + overshift_t conc = overshift(15, y, "Concrete"); + assert(conc == TO_ZERO); + // Try with -ve lhs + conc = overshift(-1, y, "Concrete"); + assert(conc == TO_ZERO); // Symbolic overshift volatile unsigned int y2; @@ -56,11 +61,15 @@ int main(int argc, char** argv) // Add constraints so only one value possible klee_assume(y2 > (y-1)); klee_assume(y2 < (y+1)); - overshift_t sym = overshift(y2, "Symbolic"); - assert( sym == TO_ZERO); + // Try with +ve lhs + overshift_t sym = overshift(15, y2, "Symbolic"); + assert(sym == TO_ZERO); + // Try with -ve lhs + sym = overshift(-1, y2, "Symbolic"); + assert(sym == TO_ZERO); // Concrete and symbolic behaviour should be the same - assert( conc == sym); + assert(conc == sym); return 0; } |