From c39ca5729eb2782e4286f3e582009e43482ebdc7 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 30 Dec 2018 09:45:13 +0800 Subject: Codegen C - Fix integer printing quirks --- src/trans/codegen_c.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 710300ce..2c40c991 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -1965,10 +1965,10 @@ namespace { break; case ::HIR::CoreType::U64: case ::HIR::CoreType::Usize: - m_of << ::std::hex << "0x" << e << ::std::dec; + m_of << ::std::hex << "0x" << e << "ull" << ::std::dec; break; case ::HIR::CoreType::U128: - m_of << ::std::hex << "0x" << e << ::std::dec; + m_of << ::std::hex << "0x" << e << "ull" << ::std::dec; break; case ::HIR::CoreType::I8: m_of << static_cast( static_cast(e) ); @@ -1982,7 +1982,7 @@ namespace { case ::HIR::CoreType::I64: case ::HIR::CoreType::I128: case ::HIR::CoreType::Isize: - m_of << static_cast(e); + m_of << static_cast(e) << "ll"; break; case ::HIR::CoreType::Char: assert(0 <= e && e <= 0x10FFFF); @@ -5629,6 +5629,16 @@ namespace { { switch(c.t) { + // TODO: These should already have been truncated/reinterpreted, but just in case. + case ::HIR::CoreType::I8: + m_of << static_cast( static_cast(c.v) ); // cast to int, because `int8_t` is printed as a `char` + break; + case ::HIR::CoreType::I16: + m_of << static_cast(c.v); + break; + case ::HIR::CoreType::I32: + m_of << static_cast(c.v); + break; case ::HIR::CoreType::I64: case ::HIR::CoreType::Isize: m_of << c.v; -- cgit v1.2.3