Commit bf1e00c1 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

Fixed bug with negative integers of size less than 64 bits

parent adab54cb
......@@ -388,8 +388,12 @@ namespace C
std::string id;
if (size <= 64) {
// Can use the string directly
if (declare_inline("<"s + current_type + ">"s + std::to_string((uint64_t)std::stoull(val, nullptr, 0)), id))
generate_call(irbuilder + "->new_const_int"s, irbuilder, id, current_type, val);
auto v = (uint64_t)std::stoull(val, nullptr, 0);
if (size < 64)
v &= ((uint64_t)1 << size) - (uint64_t)1;
if (declare_inline("<"s + current_type + ">"s + std::to_string(v), id))
generate_call(irbuilder + "->new_const_int"s, irbuilder, id, current_type, std::to_string(v));
} else {
mpz_class c {val}; // Read the integer (will auto detect base)
if (declare_inline("<"s + current_type + ">"s + c.get_str(10), id)) {
......
......@@ -333,6 +333,9 @@ namespace Runtime
if (size <= 64) {
// Can use val directly
auto v = (uint64_t)std::stoull(val, nullptr, 0);
if (size < 64)
v &= ((uint64_t)1 << size) - (uint64_t)1;
if (declare_inline("<"s + std::to_string(current_type) + ">"s + std::to_string(v), id))
irbuilder->new_const_int(irbuilder, id, current_type, v);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment