about summary refs log tree commit diff homepage
path: root/test
diff options
context:
space:
mode:
authorMartin Nowack <martin.nowack@gmail.com>2015-08-30 01:47:20 +0200
committerMartin Nowack <martin@se.inf.tu-dresden.de>2015-08-30 02:14:13 +0200
commit5c211bf969a6ae6b549d0a53daf4c99870c82210 (patch)
tree597349e681730705368f96f4124f95b109956e35 /test
parent8f6c2fd67c34a9725f79652fb6bcb24f42b0f432 (diff)
downloadklee-5c211bf969a6ae6b549d0a53daf4c99870c82210.tar.gz
Fix signed division by constant 1/ -1
Division by constant divisor get optimized
using shift and multiplication operations in STP builder.

The used method cannot be applied for divisor 1 and -1.
In that case use slow path.
Diffstat (limited to 'test')
-rw-r--r--test/regression/2015-08-30-sdiv-1.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/regression/2015-08-30-sdiv-1.c b/test/regression/2015-08-30-sdiv-1.c
new file mode 100644
index 00000000..a90df308
--- /dev/null
+++ b/test/regression/2015-08-30-sdiv-1.c
@@ -0,0 +1,19 @@
+// RUN: %llvmgcc %s -emit-llvm -g -O0 -c -o %t.bc
+// RUN: rm -rf %t.klee-out
+// RUN: %klee --output-dir=%t.klee-out -exit-on-error -solver-optimize-divides=true %t.bc
+// RUN: rm -rf %t.klee-out
+// RUN: %klee --output-dir=%t.klee-out -exit-on-error -solver-optimize-divides=false %t.bc
+
+/* Division by constant can be optimized.using mul/shift
+ * For signed division, div by 1 or -1 cannot be optimized like that.
+ */
+#include <stdint.h>
+int main() {
+  int32_t dividend;
+  klee_make_symbolic(&dividend, sizeof dividend, "Dividend");
+  if ((3 ^ (dividend & 2)) / 1)
+    return 1;
+  if ((3 ^ (dividend & 2)) / -1)
+    return 1;
+  return 0;
+}