about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2018-06-15 10:32:26 +0200
committerCristian Cadar <c.cadar@imperial.ac.uk>2018-07-10 23:26:42 +0100
commitf30de64e0babbcc68e1611ea4f191ca20c80a837 (patch)
tree57499f018cd9cce2e8e1350e4f51aeb3f9d45a24
parent44eb0541fa55f4a7a35af9eaa295ef41c46b3af1 (diff)
downloadklee-f30de64e0babbcc68e1611ea4f191ca20c80a837.tar.gz
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 <jirislaby@gmail.com>
-rw-r--r--test/Feature/arithmetic-right-overshift-sym-conc.c10
1 files 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