gccrs: Fix 128-bit non-decimal integer literal saturation#4454
Open
nsvke wants to merge 1 commit intoRust-GCC:masterfrom
Open
gccrs: Fix 128-bit non-decimal integer literal saturation#4454nsvke wants to merge 1 commit intoRust-GCC:masterfrom
nsvke wants to merge 1 commit intoRust-GCC:masterfrom
Conversation
62acb63 to
927d24e
Compare
powerboat9
approved these changes
Feb 28, 2026
powerboat9
reviewed
Feb 28, 2026
| if (current_char == 'x') | ||
| { | ||
| // hex (integer only) | ||
| return parse_non_decimal_int_literal (loc, is_x_digit, str + "x", 16); |
Collaborator
There was a problem hiding this comment.
I'm not sure what this was doing, since it's appending an x
powerboat9
reviewed
Feb 28, 2026
powerboat9
requested changes
Feb 28, 2026
Collaborator
powerboat9
left a comment
There was a problem hiding this comment.
Just need to fix the endian-dependent behavior in the test
Author
|
Thanks for the feedback! I'll update the test shortly. |
This patch replaces std::strtol with GNU MP (GMP) for arbitrary-precision parsing. Additionally, the hex literal dispatcher was corrected to avoid prepending "0x" to the internal string, ensuring compatibility with mpz_set_str. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_non_decimal_int_literal): Use GMP for base conversion to support 128-bit literals. (Lexer::parse_non_decimal_int_literals): Fix hex prefix inconsistency by passing pure string. gcc/testsuite/ChangeLog: * rust/execute/non_decimal_128_saturation.rs: New test. Signed-off-by: Enes Cevik <nsvke@proton.me>
927d24e to
cd32199
Compare
powerboat9
approved these changes
Mar 1, 2026
P-E-P
reviewed
Mar 5, 2026
| unsafe { | ||
| let hex_val: u128 = 0x10000000000000000_u128; | ||
| if (hex_val >> 64) as u8 != 1 { | ||
| abort(); |
Member
There was a problem hiding this comment.
I would change this to return 1 and check for the status using dejaGNU to avoid relying on the extern abi and keep the test somewhat minimal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses the saturation bug where large non-decimal integer literals (such as 128-bit hex, bin, and octal values) were truncated to 64-bit limits (
LONG_MAX) during the lexing phase.Key Changes:
std::strtolinLexer::parse_non_decimal_int_literalwith GNU MP (GMP) for arbitrary-precision base conversion.Lexer::parse_non_decimal_int_literalsto pass the raw string without prepending the"0x"prefix, ensuring compatibility withmpz_set_str.non_decimal_128_saturation.rs) to verify thatgcc/rust/ChangeLog:
gcc/testsuite/ChangeLog:
Closes #4453