fix: keep cast that changes operand arithmetic type in arith instructions#2906
Open
obus-globus wants to merge 1 commit into
Open
fix: keep cast that changes operand arithmetic type in arith instructions#2906obus-globus wants to merge 1 commit into
obus-globus wants to merge 1 commit into
Conversation
143e072 to
19f18c7
Compare
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.
NOTE: This is what one may call "AI slop". Feel free to close this PR if it's not up to your quality standards or even if you just aren't interested in reviewing it. I use these changes downstream on an APK and thought I might as well make a PR offering to upstream them, as your CONTRIBUTING.md doesn't say anything discouraging this.
Description
(float) a / (float) bwithintoperands decompiled toa / b, an integer division, so the result was truncated:floatDiv(1, 2)returned0.0finstead of0.5f. It reproduces on both the dex and java/class paths, since the cast is dropped inSimplifyVisitor, which is shared by all inputs.SimplifyVisitor.processCastdrops a primitive cast feeding anARITHinsn whenisArithWideUpCastreports it as unnecessary. That helper only kept casts that grow the operand register count (castToType.getRegCount() > argType.getRegCount()).intandfloatshare a register count, so theint->floatcast was dropped and jadx emitted an integer division, then relied on a widening at the result that does not happen (the division is already done inint).Keep any cast that changes the operand arithmetic type (
int/long/float/double), because operand types select the arith instruction in the result bytecode. Types narrower thanintare treated asint. The(long) i << 32case the old check handled stays covered, since it is also a type change.Includes an integration test.