more fixes for FP constants
MODIFY
ir/constant.cpp
ir/constant.cpp
@@ -43,11 +43,8 @@ expr IntConst::getTypeConstraints() const {
FloatConst::FloatConst(Type &type, double val)
: Constant(type, to_string(val)), val(val) {}
-FloatConst::FloatConst(Type &type, uint64_t val)
- : Constant(type, to_string(val)), val(val) {}
-
-FloatConst::FloatConst(Type &type, string val)
- : Constant(type, string(val)), val(move(val)) {}
+FloatConst::FloatConst(Type &type, string val, bool bit_value)
+ : Constant(type, string(val)), val(move(val)), bit_value(bit_value) {}
expr FloatConst::getTypeConstraints() const {
return Value::getTypeConstraints() &&
@@ -55,16 +52,14 @@ expr FloatConst::getTypeConstraints() const {
}
StateValue FloatConst::toSMT(State &s) const {
- if (auto n = get_if<uint64_t>(&val)) {
- return { expr::mkUInt(*n, getType().bits())
- .BV2float(getType().getDummyValue(true).value),
+ if (auto n = get_if<string>(&val)) {
+ if (!bit_value)
+ return { expr::mkNumber(n->c_str(), getType().getDummyValue(true).value),
true };
- }
-
- if (auto n = get_if<string>(&val))
return { expr::mkNumber(n->c_str(), expr::mkUInt(0, getType().bits()))
.BV2float(getType().getDummyValue(true).value),
true };
+ }
expr e;
double v = get<double>(val);

MODIFY
ir/constant.h
ir/constant.h
@@ -32,11 +32,11 @@ public:
class FloatConst final : public Constant {
- std::variant<double, uint64_t, std::string> val;
+ std::variant<double, std::string> val;
+ bool bit_value;
public:
FloatConst(Type &type, double val);
- FloatConst(Type &type, uint64_t val);
- FloatConst(Type &type, std::string val);
+ FloatConst(Type &type, std::string val, bool bit_value);
StateValue toSMT(State &s) const override;
smt::expr getTypeConstraints() const override;

MODIFY
llvm_util/utils.cpp
llvm_util/utils.cpp
@@ -265,10 +265,6 @@ Value* get_operand(llvm::Value *v,
auto &apfloat = cnst->getValueAPF();
unique_ptr<FloatConst> c;
switch (ty->getAsFloatType()->getFpType()) {
- case FloatType::Half:
- c = make_unique<FloatConst>(*ty,
- apfloat.bitcastToAPInt().getLimitedValue());
- break;
case FloatType::Float:
case FloatType::BFloat:
c = make_unique<FloatConst>(*ty, apfloat.convertToFloat());
@@ -276,9 +272,11 @@ Value* get_operand(llvm::Value *v,
case FloatType::Double:
c = make_unique<FloatConst>(*ty, apfloat.convertToDouble());
break;
+ case FloatType::Half:
case FloatType::Quad:
c = make_unique<FloatConst>(*ty,
- toString(apfloat.bitcastToAPInt(), 10, true));
+ toString(apfloat.bitcastToAPInt(), 10, false),
+ true);
break;
case FloatType::Unknown:
UNREACHABLE();

MODIFY
tools/alive_parser.cpp
tools/alive_parser.cpp
@@ -75,7 +75,7 @@ static Value& get_constant(string_view name, Type &type) {
}
static Value& get_fp_constant(string_view n, Type &t) {
- auto c = make_unique<FloatConst>(t, strtod(n.data(), nullptr));
+ auto c = make_unique<FloatConst>(t, string(n), false);
auto ret = c.get();
fn->addConstant(move(c));
return *ret;

more fixes for FP constants