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

bitwise operation takes wrong value #11580

Closed
ya-mouse opened this issue Jan 15, 2014 · 4 comments
Closed

bitwise operation takes wrong value #11580

ya-mouse opened this issue Jan 15, 2014 · 4 comments

Comments

@ya-mouse
Copy link

I'm on caf316a

Found a strange value calculation when bitwising with wrong casting:

https://gist.github.com/ya-mouse/8444726

@jfager
Copy link
Contributor

jfager commented Mar 5, 2014

This doesn't appear to be a problem anymore, can it be closed?

@alexcrichton
Copy link
Member

This still reproduces for me when compiling with optimizations.

@alexcrichton
Copy link
Member

fn main() {
    let m : [u8, ..1] = [ 0u8 ];
    println!("{}", ((m[0] >> 8) | 0) as u16);
    println!("{}", ((m[0] >> 8) | m[0]) as u16);
    assert!((((m[0] >> 8) | 0) as u16) == 0);
    assert!((((m[0] >> 8) | m[0]) as u16) == 255);
}
$ rustc -O foo.rs
$ ./foo
0
255

@thestinger
Copy link
Contributor

Bit shifts with a RHS equal to or larger than the width of the type in bytes have undefined behaviour in C and LLVM. The code here is shifting an 8-bit integer by 8 bits. This issue is reported as #10183 already.

flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 6, 2023
[`manual_let_else`]: only omit block if span is from same ctxt

Fixes rust-lang#11579.

The lint already had logic for omitting a block in `else` if a block is already present, however this didn't handle the case where the block is from a different expansion/syntax context. E.g.
```rs
macro_rules! panic_in_block {
  () => { { panic!() } }
}

let _ = match Some(1) {
  Some(v) => v,
  _ => panic_in_block!()
};
```
It would see this in its expanded form as `_ => { panic!() }` and think it doesn't have to include a block in its suggestion because it is already there, however that's not true if it's from a different expansion like in this case.

changelog: [`manual_let_else`]: only omit block in suggestion if the block is from the same expansion
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

4 participants