mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:01:07 +01:00
Fix integer literal token printing. (#2050)
Summary: An `llvm::APInt` is always treated as a signed value by `operator<<`; check [1]. This resulted in printing incorrect values for tokens that have their MSB set to 1. For example, a value 9 would be printed as -7 since its `APInt` object would be 4-bits wide. However, integer literals are always tokenized without the sign character so it is safe to treat the values as unsigned for printing pruposes. [1] https://llvm.org/doxygen/APInt_8h_source.html Co-authored-by: ergawy <kareem.ergawy@guardsquare.com>
This commit is contained in:
@@ -828,7 +828,9 @@ auto TokenizedBuffer::PrintToken(llvm::raw_ostream& output_stream, Token token,
|
||||
output_stream << ", identifier: " << GetIdentifier(token).index_;
|
||||
break;
|
||||
case TokenKind::IntegerLiteral():
|
||||
output_stream << ", value: `" << GetIntegerLiteral(token) << "`";
|
||||
output_stream << ", value: `";
|
||||
GetIntegerLiteral(token).print(output_stream, /*isSigned=*/false);
|
||||
output_stream << "`";
|
||||
break;
|
||||
case TokenKind::RealLiteral():
|
||||
output_stream << ", value: `" << GetRealLiteral(token) << "`";
|
||||
|
||||
Reference in New Issue
Block a user