Fix sign-extension of 64-bit literals #213
Open
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.
Context
When
SUPPORT_64_BIT_LITERALSis not enabled,INTEGERnodes store the negation of the integer value. This is done to support the full range of 32-bit signed integers, since the positive value2147483648cannot be represented as a positive signed 32-bit integer.To get the actual value, it must be negated. If the negated value is
-2147483648, negating it produces2147483648, which overflows the 32-bit signed integer range (assuming the host platform uses 32-bit integers) and loops back to-2147483648. Additionally, for 64-bit targets, the value must be sign-extended to 64-bits, which is done by left shifting by 31.On platforms with 32-bit integers, the two's complement representation of 2147483648 is the same as -2147483648's two's complement, 0x80000000 in hex, and so everything works out.
On platforms with larger integers, such as some shells, the value
2147483648is representable as a positive integer, and so negating-2147483648produces2147483648, which produces an invalid sign-extended value when shifted. Sign-extension is only performed when targeting 64-bit platforms, where2147483648 >> 31evaluates to 1.This PR changes the sign-extension to no longer assume exactly 32-bit integers.