-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[ConstantInt] Disable implicit truncation in ConstantInt::get() #171456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nikic
wants to merge
26
commits into
llvm:main
Choose a base branch
from
nikic:constantint-implicit-trunc-false
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
nikic
added a commit
that referenced
this pull request
Dec 12, 2025
Explicitly cast the value to (int) before negating, so it gets properly sign extended. Otherwise we end up with a large unsigned value instead of a negative value for large bit widths. This was found while working on #171456.
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Dec 12, 2025
Explicitly cast the value to (int) before negating, so it gets properly sign extended. Otherwise we end up with a large unsigned value instead of a negative value for large bit widths. This was found while working on llvm/llvm-project#171456.
anonymouspc
pushed a commit
to anonymouspc/llvm
that referenced
this pull request
Dec 15, 2025
Explicitly cast the value to (int) before negating, so it gets properly sign extended. Otherwise we end up with a large unsigned value instead of a negative value for large bit widths. This was found while working on llvm#171456.
nikic
added a commit
that referenced
this pull request
Dec 16, 2025
Use getSigned() to create the 1 or -1 constant, so it gets properly sign extended. This miscompile was found while working on #171456.
To limit scope.
To reduce scope.
For now, we should implicitly truncate overflowing allocation sizes when expanding GEPs, like we do in other places.
This value may be -1.
It's okay if the pattern value gets truncated here, it's a splat.
For non-fragile this is a negative value.
This may be -1 for incompete array types.
0eb2003 to
9e2cace
Compare
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Dec 16, 2025
…172301) Use getSigned() to create the 1 or -1 constant, so it gets properly sign extended. This miscompile was found while working on llvm/llvm-project#171456.
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
The value is always stored as an unsigned number, even if the char type is signed, so we have to allow truncation here.
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.
Disable implicit truncation in the ConstantInt constructor by default. This means that it needs to be passed a signed/unsigned (depending on the IsSigned flag) value matching the bit width.
The intention is to prevent the recurring bug where people write something like
ConstantInt::get(Ty, -1), and this "works" untilTyis larger than 64-bit and then the value is incorrect due to missing type extension.This is the continuation of #112670, which originally allowed implicit truncation in this constructor to reduce initial scope of the change.
This PR is WIP. Most parts will be landed separately.