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

op_shl and op_shr API is unsafe in native backend #1607

Open
illusory0x0 opened this issue Feb 7, 2025 · 0 comments
Open

op_shl and op_shr API is unsafe in native backend #1607

illusory0x0 opened this issue Feb 7, 2025 · 0 comments

Comments

@illusory0x0
Copy link
Contributor

illusory0x0 commented Feb 7, 2025

https://en.cppreference.com/w/c/language/operator_arithmetic

The behavior is undefined if rhs is negative or is greater or equal the number of bits in the promoted lhs.

///|
pub fn Int::op_shl(self : Int, other : Int) -> Int = "%i32_shl"

///|
pub fn Int::op_shr(self : Int, other : Int) -> Int = "%i32_shr"

I recommend the following API

///|
pub fn Int::op_shl(self : Int, other : UInt) -> Int

///|
pub fn Int::op_shr(self : Int, other : UInt) -> Int

and if greater or equal the number of bits in the promoted lhs, I think we need to panic in all backend.

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

No branches or pull requests

1 participant