about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorCristian Cadar <cristic@cs.stanford.edu>2012-07-20 15:29:12 +0000
committerCristian Cadar <cristic@cs.stanford.edu>2012-07-20 15:29:12 +0000
commitde7d94e27bc92292c74fd045b2565581694314a7 (patch)
treee05f76d3cddafceff5d3262f3f5888176400bca2
parent69a3e3221bf6bb8f33a4f5180bba38bfdc98f27c (diff)
downloadklee-de7d94e27bc92292c74fd045b2565581694314a7.tar.gz
Fixed bug FPToSI bug reported by Peng Li. Added a simple test case.
git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@160547 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Core/Executor.cpp2
-rw-r--r--test/Feature/FloatingPt.c23
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index c6bd379a..278f8941 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -2148,7 +2148,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
     llvm::APFloat Arg(arg->getAPValue());
     uint64_t value = 0;
     bool isExact = true;
-    Arg.convertToInteger(&value, resultType, false,
+    Arg.convertToInteger(&value, resultType, true,
                          llvm::APFloat::rmTowardZero, &isExact);
     bindLocal(ki, state, ConstantExpr::alloc(value, resultType));
     break;
diff --git a/test/Feature/FloatingPt.c b/test/Feature/FloatingPt.c
new file mode 100644
index 00000000..bde9e19b
--- /dev/null
+++ b/test/Feature/FloatingPt.c
@@ -0,0 +1,23 @@
+// RUN: %llvmgcc %s -emit-llvm -O0 -c -o %t1.bc
+// RUN: %klee --exit-on-error %t1.bc
+
+#include <assert.h>
+
+int main() {
+  double a1 = -1.1;
+  double a2 = 1.2;
+  
+  int b1 = (int) a1;
+  assert(b1 == -1);
+  
+  int b2 = (int) a2;
+  assert(b2 == 1);
+
+  a1 = (double) b1;
+  assert(a1 == -1);
+
+  a2 = (double) b2;
+  assert(a2 == 1);
+
+  return 0;
+}