Skip to content

Commit

Permalink
Fix radix of decimal immediates (#8865)
Browse files Browse the repository at this point in the history
Decimal immediates incorrectly parsed as hex digits.
  • Loading branch information
thaliaarchi authored Jun 24, 2024
1 parent 0f3dcd1 commit 7112d93
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cranelift/codegen/src/ir/immediates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ fn parse_u64(s: &str) -> Result<u64, &'static str> {
} else {
// Decimal number, possibly negative.
for ch in s.chars() {
match ch.to_digit(16) {
match ch.to_digit(10) {
Some(digit) => {
digits += 1;
match value.checked_mul(10) {
Expand Down Expand Up @@ -1270,6 +1270,8 @@ mod tests {
parse_err::<Imm64>(" 0", "Invalid character in decimal number");
parse_err::<Imm64>("--", "Invalid character in decimal number");
parse_err::<Imm64>("-0x-", "Invalid character in hexadecimal number");
parse_err::<Imm64>("abc", "Invalid character in decimal number");
parse_err::<Imm64>("-abc", "Invalid character in decimal number");

// Hex count overflow.
parse_err::<Imm64>("0x0_0000_0000_0000_0000", "Too many hexadecimal digits");
Expand Down Expand Up @@ -1310,6 +1312,8 @@ mod tests {
parse_err::<Uimm64>("-0x-", "Invalid character in hexadecimal number");
parse_err::<Uimm64>("-0", "Invalid character in decimal number");
parse_err::<Uimm64>("-1", "Invalid character in decimal number");
parse_err::<Uimm64>("abc", "Invalid character in decimal number");
parse_err::<Uimm64>("-abc", "Invalid character in decimal number");

// Hex count overflow.
parse_err::<Uimm64>("0x0_0000_0000_0000_0000", "Too many hexadecimal digits");
Expand Down

0 comments on commit 7112d93

Please sign in to comment.