Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Solver/Z3BitvectorBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,8 @@ Z3ASTHandle Z3BitvectorBuilder::castToBitVector(const Z3ASTHandle &e) {
Z3SortHandle currentSort = Z3SortHandle(Z3_get_sort(ctx, e), ctx);
Z3_sort_kind kind = Z3_get_sort_kind(ctx, currentSort);
switch (kind) {
case Z3_BOOL_SORT:
return Z3ASTHandle(Z3_mk_ite(ctx, e, bvOne(1), bvZero(1)), ctx);
case Z3_BV_SORT:
// Already a bitvector
return e;
Expand Down
35 changes: 35 additions & 0 deletions test/regression/2023-09-05-bool-to-fp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %clang %s -g -emit-llvm %O0opt -c -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --optimize --output-dir=%t.klee-out %t1.bc 2>&1 | FileCheck %s

#include "klee/klee.h"

extern void abort(void);
extern void __assert_fail(const char *, const char *, unsigned int, const char *) __attribute__((__nothrow__, __leaf__)) __attribute__((__noreturn__));
void reach_error() { __assert_fail("0", "float3.c", 3, "reach_error"); }

double d = 0.0;

void f1() {
d = 1.0;
}

int main() {
int x = 2;

if (klee_int("a"))
x = 4;

(void)f1();

d += (x == 2);

d += (x > 3);

if (!(d == 2.0)) {
reach_error();
abort();
}
}

// CHECK: KLEE: done: generated tests = 1