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

Bit-shift lint errors on cross-compiles #18587

Closed
alexcrichton opened this issue Nov 3, 2014 · 12 comments · Fixed by #18593
Closed

Bit-shift lint errors on cross-compiles #18587

alexcrichton opened this issue Nov 3, 2014 · 12 comments · Fixed by #18593
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@alexcrichton
Copy link
Member

When crossing from 32-to-64 bit architectures the lint will fire erroneously, causing the standard library not to compile:

rustc: i686-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libcore
/Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libcore/num/int_macros.rs:28:21: 28:45 error: bitshift exceeds the type's number of bits, #[deny(exceeding_bitshifts)] on by default
/Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libcore/num/int_macros.rs:28 pub const MIN: $T = (-1 as $T) << (BITS - 1);
                                                                                                                ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libcore/num/int_macros.rs:14:1: 35:3 note: in expansion of int_module!
/Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libcore/num/int.rs:17:33: 17:53 note: expansion site
error: aborting due to previous error
make: *** [i686-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/stamp.core] Error 101

What's happening is that the lint is picking up the number of bits for the type int and uint from int::BITS and uint::BITS, but these are not the target architecture's number of bits.

cc @hirschenberger, this will block a new nightly tonight.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Nov 3, 2014
There's currently a bug in it which fires erroneously on cross compiles,
preventing new nightlies from being generated. This can be reset back to Deny
once it's been fixed.

cc rust-lang#18587
@hirschenberger
Copy link
Contributor

How can I find out the target architecture on cross compiles?

@alexcrichton
Copy link
Member Author

I don't know off the top of my head what the best way is to do so, but you can take a look at targ_cfg in Session and head from there. I'm sure there's also many examples in rustc::middle::trans

@alexcrichton alexcrichton added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Nov 3, 2014
@hirschenberger
Copy link
Contributor

Ok, I think I found it, working on it...

@alexcrichton
Copy link
Member Author

Thanks @hirschenberger!

@hirschenberger
Copy link
Contributor

Is it possible to add cross compilation tests?

@alexcrichton
Copy link
Member Author

Sadly not currently :(. In #18206 I don't see a test for int or uint, so you could just add tests inside #[cfg(target_word_size = "...")] functions and it should be good for now. These will get auto-tested on nightlies, just not on normal bors builds.

@hirschenberger
Copy link
Contributor

Do you think this will be enough?

#[cfg(target_word_size = "32")]
      let n = 1i << 32; //~ ERROR: bitshift exceeds the type's number of bits
#[cfg(target_word_size = "64")]
      let n = 1i << 64; //~ ERROR: bitshift exceeds the type's number of bits

bors added a commit that referenced this issue Nov 3, 2014
There's currently a bug in it which fires erroneously on cross compiles,
preventing new nightlies from being generated. This can be reset back to Deny
once it's been fixed.

cc #18587
@alexcrichton
Copy link
Member Author

Looks good to me! I'd add one for uint as well just to ensure it's covered.

@hirschenberger
Copy link
Contributor

Sry I have a little syntax Problem:

error: expected item after attributes

      #[cfg(target_word_size = "32")]
      {
        let n = 1i << 32; //~ ERROR: bitshift exceeds the type's number of bits
        let n = 1u << 32; //~ ERROR: bitshift exceeds the type's number of bits
      }

doesn't work

@alexcrichton
Copy link
Member Author

It's ok if you want to just wrap it up in something like:

#[cfg(target_word_size = "32")]
fn dead_but_still_linted() {
        let n = 1i << 32; //~ ERROR: bitshift exceeds the type's number of bits
        let n = 1u << 32; //~ ERROR: bitshift exceeds the type's number of bits
}

@hirschenberger
Copy link
Contributor

@alexcrichton Is it working for all cross compiles? Can we switch it to Deny again?

@alexcrichton
Copy link
Member Author

I think so, sure!

hirschenberger added a commit to hirschenberger/rust that referenced this issue Nov 11, 2014
bors added a commit that referenced this issue Nov 13, 2014
lnicola pushed a commit to lnicola/rust that referenced this issue Dec 11, 2024
fix: Fix syntax fixup inserting unnecessary semicolons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants