fix creation of Half constants
MODIFY
ir/constant.cpp
ir/constant.cpp
@@ -43,8 +43,8 @@ expr IntConst::getTypeConstraints() const {
FloatConst::FloatConst(Type &type, double val)
: Constant(type, to_string(val)), val(val) {}
-FloatConst::FloatConst(Type &type, std::string &&val)
- : Constant(type, string(val)), val(move(val)) {}
+FloatConst::FloatConst(Type &type, uint64_t val)
+ : Constant(type, to_string(val)), val(val) {}
expr FloatConst::getTypeConstraints() const {
return Value::getTypeConstraints() &&
@@ -52,9 +52,11 @@ expr FloatConst::getTypeConstraints() const {
}
StateValue FloatConst::toSMT(State &s) const {
- if (auto str = get_if<string>(&val))
- return { expr::mkNumber(str->c_str(), getType().getDummyValue(true).value),
+ if (auto n = get_if<uint64_t>(&val)) {
+ return { expr::mkUInt(*n, getType().bits())
+ .BV2float(getType().getDummyValue(true).value),
true };
+ }
expr e;
double v = get<double>(val);

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

MODIFY
llvm_util/utils.cpp
llvm_util/utils.cpp
@@ -161,12 +161,10 @@ Value* get_operand(llvm::Value *v) {
auto &apfloat = cnst->getValueAPF();
unique_ptr<FloatConst> c;
switch (ty->getAsFloatType()->getFpType()) {
- case FloatType::Half: {
- llvm::SmallString<32> str;
- apfloat.toString(str);
- c = make_unique<FloatConst>(*ty, str.str());
+ case FloatType::Half:
+ c = make_unique<FloatConst>(*ty,
+ apfloat.bitcastToAPInt().getLimitedValue());
break;
- }
case FloatType::Float:
c = make_unique<FloatConst>(*ty, apfloat.convertToFloat());
break;

fix creation of Half constants