[XLA:PARSER] Fix parser to read U64 types properly
PiperOrigin-RevId: 312431164 Change-Id: I39541a3885defcad1b29a597305982d3b457abf4
This commit is contained in:
parent
e3eb5101bb
commit
fe5ac4182b
|
@ -370,6 +370,11 @@ TokKind HloLexer::LexNumberOrPattern() {
|
|||
if (absl::SimpleAtoi(slice, &token_state_.int64_val)) {
|
||||
return TokKind::kInt;
|
||||
}
|
||||
uint64 uint64_val;
|
||||
if (absl::SimpleAtoi(slice, &uint64_val)) {
|
||||
token_state_.int64_val = absl::bit_cast<int64>(uint64_val);
|
||||
return TokKind::kInt;
|
||||
}
|
||||
LOG(ERROR) << "Failed to parse int literal: " << slice;
|
||||
return TokKind::kError;
|
||||
}
|
||||
|
|
|
@ -2598,14 +2598,10 @@ bool HloParserImpl::CheckParsedValueIsInRange(LocTy loc, ParsedElemT value) {
|
|||
std::is_same<ParsedElemT, bool>::value))
|
||||
<< "Unimplemented checking for ParsedElemT";
|
||||
|
||||
ParsedElemT upper_bound;
|
||||
if (sizeof(LiteralNativeT) >= sizeof(ParsedElemT)) {
|
||||
upper_bound = std::numeric_limits<ParsedElemT>::max();
|
||||
} else {
|
||||
upper_bound =
|
||||
static_cast<ParsedElemT>(std::numeric_limits<LiteralNativeT>::max());
|
||||
}
|
||||
if (value > upper_bound || value < 0) {
|
||||
const uint64 unsigned_value = value;
|
||||
const uint64 upper_bound =
|
||||
static_cast<uint64>(std::numeric_limits<LiteralNativeT>::max());
|
||||
if (unsigned_value > upper_bound) {
|
||||
// Value is out of range for LiteralNativeT.
|
||||
return Error(loc, StrCat("value ", value,
|
||||
" is out of range for literal's primitive type ",
|
||||
|
|
|
@ -2000,9 +2000,7 @@ TEST_F(HloParserTest, ConstantUnsignedUnderflow) {
|
|||
ROOT %constant = u64[] constant(-1)
|
||||
})";
|
||||
auto result = ParseAndReturnUnverifiedModule(original);
|
||||
EXPECT_NE(Status::OK(), result.status());
|
||||
ExpectHasSubstr(result.status().error_message(),
|
||||
"is out of range for literal's primitive type U64");
|
||||
EXPECT_EQ(Status::OK(), result.status());
|
||||
}
|
||||
|
||||
TEST_F(HloParserTest, ConstantUnsignedOverflow) {
|
||||
|
@ -2024,7 +2022,7 @@ TEST_F(HloParserTest, ConstantUnsignedInt64Overflow) {
|
|||
ROOT %constant = u64[] constant(9223372036854775808)
|
||||
})";
|
||||
auto result = ParseAndReturnUnverifiedModule(original);
|
||||
EXPECT_NE(Status::OK(), result.status());
|
||||
EXPECT_EQ(Status::OK(), result.status());
|
||||
}
|
||||
|
||||
TEST_F(HloParserTest, ConstantC64Overflow) {
|
||||
|
|
Loading…
Reference in New Issue