cast_possible_truncation: Support size_of, align_of, and size_of_val#15488
Open
RunDevelopment wants to merge 4 commits into
Open
cast_possible_truncation: Support size_of, align_of, and size_of_val#15488RunDevelopment wants to merge 4 commits into
size_of, align_of, and size_of_val#15488RunDevelopment wants to merge 4 commits into
Conversation
Collaborator
|
Lintcheck changes for c5a67a8
This comment will be updated if you push new changes |
Collaborator
|
☔ The latest upstream changes (possibly e9b7045) made this pull request unmergeable. Please resolve the merge conflicts. |
blyxyas
requested changes
Sep 5, 2025
Comment on lines
+518
to
+522
| ExprKind::Call(callee, [_]) => match self.get_fn_diagnostic_name(callee) { | ||
| // `align_of_val` doesn't have a diagnostic name, unfortunately. | ||
| // Some(sym::mem_align_of_val) => self.align_of_call(callee), | ||
| Some(sym::mem_size_of_val) => self.size_of_call(callee), | ||
| _ => None, |
Member
There was a problem hiding this comment.
See the other comment
Suggested change
| ExprKind::Call(callee, [_]) => match self.get_fn_diagnostic_name(callee) { | |
| // `align_of_val` doesn't have a diagnostic name, unfortunately. | |
| // Some(sym::mem_align_of_val) => self.align_of_call(callee), | |
| Some(sym::mem_size_of_val) => self.size_of_call(callee), | |
| _ => None, |
Comment on lines
+508
to
+517
| ExprKind::Call(callee, []) => match self.get_fn_diagnostic_name(callee) { | ||
| Some(sym::i8_legacy_fn_max_value) => Some(Constant::Int(i8::MAX as u128)), | ||
| Some(sym::i16_legacy_fn_max_value) => Some(Constant::Int(i16::MAX as u128)), | ||
| Some(sym::i32_legacy_fn_max_value) => Some(Constant::Int(i32::MAX as u128)), | ||
| Some(sym::i64_legacy_fn_max_value) => Some(Constant::Int(i64::MAX as u128)), | ||
| Some(sym::i128_legacy_fn_max_value) => Some(Constant::Int(i128::MAX as u128)), | ||
| Some(sym::mem_align_of) => self.align_of_call(callee), | ||
| Some(sym::mem_size_of) => self.size_of_call(callee), | ||
| _ => None, | ||
| }, |
Member
There was a problem hiding this comment.
[..] The rest pattern also allows for zero-sized arrays, no need for the extra branch.
Suggested change
| ExprKind::Call(callee, []) => match self.get_fn_diagnostic_name(callee) { | |
| Some(sym::i8_legacy_fn_max_value) => Some(Constant::Int(i8::MAX as u128)), | |
| Some(sym::i16_legacy_fn_max_value) => Some(Constant::Int(i16::MAX as u128)), | |
| Some(sym::i32_legacy_fn_max_value) => Some(Constant::Int(i32::MAX as u128)), | |
| Some(sym::i64_legacy_fn_max_value) => Some(Constant::Int(i64::MAX as u128)), | |
| Some(sym::i128_legacy_fn_max_value) => Some(Constant::Int(i128::MAX as u128)), | |
| Some(sym::mem_align_of) => self.align_of_call(callee), | |
| Some(sym::mem_size_of) => self.size_of_call(callee), | |
| _ => None, | |
| }, | |
| ExprKind::Call(callee, [..]) => match self.get_fn_diagnostic_name(callee) { | |
| Some(sym::i8_legacy_fn_max_value) => Some(Constant::Int(i8::MAX as u128)), | |
| Some(sym::i16_legacy_fn_max_value) => Some(Constant::Int(i16::MAX as u128)), | |
| Some(sym::i32_legacy_fn_max_value) => Some(Constant::Int(i32::MAX as u128)), | |
| Some(sym::i64_legacy_fn_max_value) => Some(Constant::Int(i64::MAX as u128)), | |
| Some(sym::i128_legacy_fn_max_value) => Some(Constant::Int(i128::MAX as u128)), | |
| Some(sym::mem_align_of) => self.align_of_call(callee), | |
| Some(sym::mem_size_of) | Some(sym::mem_size_of_val)=> self.size_of_call(callee), | |
| _ => None, | |
| }, |
| } | ||
| } | ||
|
|
||
| fn align_of_call(&self, callee: &Expr<'_>) -> Option<Constant<'tcx>> { |
Member
There was a problem hiding this comment.
Could you add some documentation here for these two functions?
Member
|
ping @RunDevelopment 🏓 I'm not sure if you saw my review or if it just flew under the radar? |
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.
fixes parts of #9613, related to #12962
Unlike #12962, I added support for
size_of,align_of, andsize_of_valtoConstEval, so all lints using it benefit from this change.cast_possible_truncationitself changed relatively little. Functions calls are now delegated to const eval and ptr-sized to fixed-sized casts now considerfrom_nbits.changelog: [
cast_possible_truncation]: supportsize_of,align_of, andsize_of_valMy intention with this PR is not to superceed #12962, but to get in a simple improvement while I work on #15342.