Fix unnecessary transmute and unnecessary unsafe block warnings on bitfield codegen#3388
Open
armoha wants to merge 3 commits into
Open
Fix unnecessary transmute and unnecessary unsafe block warnings on bitfield codegen#3388armoha wants to merge 3 commits into
armoha wants to merge 3 commits into
Conversation
Author
|
CI fails because |
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.
Fix #2807 and #3241 (comment)
PR #3335 replaced
transmutewithas _in the union branch getter/setter and the non-union setter, and removed the unsafe block from the union branch. It left non-union getter and raw getter, emittingunsafe { transmute(...) }and triggeringunnecessary_transmuteswarning for integer (#2807). It replacedtransmutewithval as _for non-union setter and keptunsafeblock which is required for Rust unions (its field access is unsafe) but redundant for the rest of cases (#3241 (comment)).This PR type-dispatches the non-union getter codegen, and removes unnecessary unsafe block from the non-union setter. It dispatches on
bitfield_ty.canonical_type(ctx).kind()instead ofbitfield_ty.kind()to resolveAlias/Elaboratedwrappers clang applies.unsafe { transmute(get_const() as u32) }(unnecessary transmutes) ->get_const() as u32 as _unsafe { transmute(get_const() as u8) }->get_const() as u8 != 0unsafe { transmute(get_const() as u32) }unsafe { let val: u32 = val as _; self._bitfield_1.set_const(val as u64) }let val: u32 = val as _; self._bitfield_1.set_const(val as u64)