Skip to content
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

Fix invalid codegen on small to long int cast #1921

Merged
merged 3 commits into from
Jun 24, 2021
Merged

Fix invalid codegen on small to long int cast #1921

merged 3 commits into from
Jun 24, 2021

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Jun 23, 2021

fixes #1911

  • I've read the contributing guidelines

Comment on lines +1355 to +1360
// sign extensions overflow if result can have high garbage bits in the target type
case UnaryOp.Extend8I32: return type.size < (type.isUnsignedIntegerValue ? 32 : 8);
case UnaryOp.Extend8I64: return type.size < (type.isUnsignedIntegerValue ? 64 : 8);
case UnaryOp.Extend16I32: return type.size < (type.isUnsignedIntegerValue ? 32 : 16);
case UnaryOp.Extend16I64: return type.size < (type.isUnsignedIntegerValue ? 64 : 16);
case UnaryOp.Extend32I64: return type.size < (type.isUnsignedIntegerValue ? 64 : 32);
Copy link
Member Author

@dcodeIO dcodeIO Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a comment here for review, by example of i32.extend16_s:

If the target type is unsigned, an i32.extend16_s can yield high garbage bits if the target type is smaller than u32. u32 naturally does not care about garbage bits, but any smaller unsigned integer could have garbage high 1s after the instruction.

If the target type is signed, an i32.extend16_s can yield high garbage 0s after leading 1s if the target type is smaller than i16. If the target type is i16 or larger, the instruction would set all high bits to either 0 or 1, which makes the value valid regardless.

@dcodeIO dcodeIO requested a review from MaxGraey June 23, 2021 23:20
@dcodeIO dcodeIO merged commit 495814f into main Jun 24, 2021
@dcodeIO dcodeIO deleted the issue-1911 branch June 29, 2021 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wasm-validator error: i64 != i32: binary child types must be equal
2 participants