about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJulian Büning <julian.buening@comsys.rwth-aachen.de>2020-09-18 18:14:56 +0200
committerCristian Cadar <c.cadar@imperial.ac.uk>2020-10-09 21:46:06 +0100
commit0769caf8bbf0bc6ea3c681e5af7d79291fae2e2f (patch)
treeb8f06e501c5b9e8e1554a43c95d4ca092fdcb9a8
parent6e0209e74ef814aa27af2add01d22284817c3d73 (diff)
downloadklee-0769caf8bbf0bc6ea3c681e5af7d79291fae2e2f.tar.gz
implement fneg instruction
-rw-r--r--lib/Core/Executor.cpp14
-rw-r--r--test/Feature/FNeg.ll19
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index 7fac4fa4..de35710f 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -2465,6 +2465,20 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
     // Floating point instructions
 
+#if LLVM_VERSION_CODE >= LLVM_VERSION(8, 0)
+  case Instruction::FNeg: {
+    ref<ConstantExpr> arg =
+        toConstant(state, eval(ki, 0, state).value, "floating point");
+    if (!fpWidthToSemantics(arg->getWidth()))
+      return terminateStateOnExecError(state, "Unsupported FNeg operation");
+
+    llvm::APFloat Res(*fpWidthToSemantics(arg->getWidth()), arg->getAPValue());
+    Res = llvm::neg(Res);
+    bindLocal(ki, state, ConstantExpr::alloc(Res.bitcastToAPInt()));
+    break;
+  }
+#endif
+
   case Instruction::FAdd: {
     ref<ConstantExpr> left = toConstant(state, eval(ki, 0, state).value,
                                         "floating point");
diff --git a/test/Feature/FNeg.ll b/test/Feature/FNeg.ll
new file mode 100644
index 00000000..cdea6aaa
--- /dev/null
+++ b/test/Feature/FNeg.ll
@@ -0,0 +1,19 @@
+; REQUIRES: geq-llvm-8.0
+; RUN: %llvmas %s -o %t.bc
+; RUN: rm -rf %t.klee-out
+; RUN: %klee -exit-on-error -output-dir=%t.klee-out -optimize=false %t.bc
+
+define i32 @main() {
+  %1 = fneg double 2.000000e-01
+  %2 = fcmp oeq double %1, -2.000000e-01
+  br i1 %2, label %success, label %fail
+
+success:
+  ret i32 0
+
+fail:
+  call void @abort()
+  unreachable
+}
+
+declare void @abort() noreturn nounwind