From f30de64e0babbcc68e1611ea4f191ca20c80a837 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Fri, 15 Jun 2018 10:32:26 +0200 Subject: test: remove undefined behaviour Shifting negative values is implementation-defined. Shifting by equal number of the bits as is the size of the type is undefined. So fix both of these. This fixes #911. Signed-off-by: Jiri Slaby --- test/Feature/arithmetic-right-overshift-sym-conc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/Feature/arithmetic-right-overshift-sym-conc.c b/test/Feature/arithmetic-right-overshift-sym-conc.c index 7af6f9d7..6a9bbc21 100644 --- a/test/Feature/arithmetic-right-overshift-sym-conc.c +++ b/test/Feature/arithmetic-right-overshift-sym-conc.c @@ -13,6 +13,8 @@ typedef enum UNKNOWN } overshift_t; +#define INT_31_BITS (0xffffffff >> 1) + // We're using signed ints so should be doing // arithmetic right shift. // lhs should be a constant @@ -20,7 +22,7 @@ int overshift(signed int lhs, volatile unsigned int y, const char * type) { overshift_t ret; volatile signed int x = lhs; - unsigned int limit = sizeof(x)*8; + unsigned int limit = sizeof(x)*8 - 1; assert(!klee_is_symbolic(x)); volatile signed int result; @@ -47,12 +49,12 @@ int overshift(signed int lhs, volatile unsigned int y, const char * type) int main(int argc, char** argv) { - volatile unsigned int y = sizeof(unsigned int)*8; + volatile unsigned int y = sizeof(unsigned int)*8 - 1; // Try with +ve lhs overshift_t conc = overshift(15, y, "Concrete"); assert(conc == TO_ZERO); // Try with -ve lhs - conc = overshift(-1, y, "Concrete"); + conc = overshift(INT_31_BITS, y, "Concrete"); assert(conc == TO_ZERO); // Symbolic overshift @@ -65,7 +67,7 @@ int main(int argc, char** argv) overshift_t sym = overshift(15, y2, "Symbolic"); assert(sym == TO_ZERO); // Try with -ve lhs - sym = overshift(-1, y2, "Symbolic"); + sym = overshift(INT_31_BITS, y2, "Symbolic"); assert(sym == TO_ZERO); // Concrete and symbolic behaviour should be the same -- cgit 1.4.1