Add error diagnostic for integer literals that don't fit into uint64_t#9208
Merged
expipiplus1 merged 6 commits intoshader-slang:masterfrom Dec 8, 2025
Merged
Conversation
UndefinedBehaviorSanitizer reported a signed integer overflow in
`getIntegerLiteralValue`. The root cause is that the
`IntegerLiteralValue` type is an alias for `int64_t` and the Slang
compiler doesn't check for overflows when parsing integer literals into
this type.
As a result, in the following example, Slang lets the value of `x`
silently overflow to 0:
```slang
int x = 18446744073709551616;
```
For comparison, by default, Clang emits an error:
```
a.c:1:9: error: integer literal is too large to be represented in any integer type
1 | int x = 18446744073709551616;
| ^
1 error generated.
```
And GCC emits a warning:
```
a.c:1:9: warning: integer constant is too large for its type
1 | int x = 18446744073709551616;
| ^~~~~~~~~~~~~~~~~~~~
```
This PR follows Clang by adding an error diagnostic instead of a
warning.
Since the lexer scans the minus sign of negative numbers as a separate
token, an integer literal is always a positive number. When lexing the
value of `INT64_MIN`, the integer literal is thus `INT64_MAX + 1`, which
overflows when stored into an `IntegerLiteralValue`/`int64_t` despite
being valid. Therefore, this PR changes `getIntegerLiteralValue` to use
`uint64_t` internally.
Related to shader-slang#9099.
…`uint64_t` Add test
…`uint64_t` Fix test comment grammar
jkwak-work
reviewed
Dec 3, 2025
Collaborator
|
Can you leave a comment as following? |
Contributor
Author
Sure, but wouldn't |
expipiplus1
approved these changes
Dec 5, 2025
github-merge-queue bot
pushed a commit
that referenced
this pull request
Dec 10, 2025
When generating the release note, the script was missing the new line characters for the breaking changes. The following is an example of the problem: > === Breaking changes === 72761cc Add error diagnostic for integer literals that don't fit into uint64_t (#9208 Remove the deprecated hlsl_coopvec_poc capability that was for POC CoopVec (#9213 Add type-flow analysis pass for specialized dynamic dispatch (#7968) With this PR, it will be fixed as below: >=== Breaking changes === 72761cc Add error diagnostic for integer literals that don't fit into uint64_t (#9208) cc73e8d Remove the deprecated hlsl_coopvec_poc capability that was for POC CoopVec (#9213) 4280f24 Add type-flow analysis pass for specialized dynamic dispatch (#7968)
gtong-nv
pushed a commit
that referenced
this pull request
Dec 15, 2025
When generating the release note, the script was missing the new line characters for the breaking changes. The following is an example of the problem: > === Breaking changes === 72761cc Add error diagnostic for integer literals that don't fit into uint64_t (#9208 Remove the deprecated hlsl_coopvec_poc capability that was for POC CoopVec (#9213 Add type-flow analysis pass for specialized dynamic dispatch (#7968) With this PR, it will be fixed as below: >=== Breaking changes === 72761cc Add error diagnostic for integer literals that don't fit into uint64_t (#9208) cc73e8d Remove the deprecated hlsl_coopvec_poc capability that was for POC CoopVec (#9213) 4280f24 Add type-flow analysis pass for specialized dynamic dispatch (#7968)
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.
UndefinedBehaviorSanitizer reported a signed integer overflow in
getIntegerLiteralValue. The root cause is that theIntegerLiteralValuetype is an alias forint64_tand the Slang compiler doesn't check for overflows when parsing integer literals into this type.As a result, in the following example, Slang lets the value of
xsilently overflow to 0:For comparison, by default, Clang emits an error:
And GCC emits a warning:
This PR follows Clang by adding an error diagnostic instead of a warning.
Since the lexer scans the minus sign of negative numbers as a separate token, an integer literal is always a positive number. When lexing the value of
INT64_MIN, the integer literal is thusINT64_MAX + 1, which overflows when stored into anIntegerLiteralValue/int64_tdespite being valid. Therefore, this PR changesgetIntegerLiteralValueto useuint64_tinternally.Related to #9099.