-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Slice length becomes random between nightly-2021-03-04 and nightly-2021-03-05 #82859
Comments
Are you able to share a code snippet that reproduces your bug, even a long example is fine for now? |
Very likely caused by LLVM upgrade. |
I'm having lunch now, but I'll see what I can do afterwards :) |
So far, my only progress is that for item in my_iter.iter() {
...
} works whilst the following does not: my_iter.iter().for_each(|item| {
...
}); Again, adding a |
@Stupremee @nikic Ok, I finally was able to reduce this bug to its bones - here is the code (it turned out to be quite different than what I had originally expected): pub struct S;
fn check() -> bool {
true
}
impl S {
fn impl_get_slice(&self, _val: &()) -> &[()] {
&[]
}
#[inline(always)]
fn get_slice(&self, val: &()) -> &[()] {
if !check() {
panic!("panic")
};
let run = || { self.impl_get_slice(val) };
let ret = run();
ret
}
}
fn main() {
let output;
let s = S;
output = s.get_slice(&()).len();
println!("{}", output);
} You can see that on the current nightly, this snippet prints a random value: My best guess is that in debug mode (this bug does not occur in release), we are actually trying to read the length of our slice |
Slightly smaller: fn indirect_get_slice() -> &'static [usize] {
&[]
}
#[inline(always)]
fn get_slice() -> &'static [usize] {
let ret = indirect_get_slice();
ret
}
fn main() {
let output = get_slice().len();
println!("{}", output);
} |
Hmm, this also happens in debug mode for me (both with the larger and smaller example). |
It doesn't work in release mode. It only works in debug mode |
This requires |
This is likely the same issue as #82833. |
Assigning |
Code
I tried this code (thanks to @jyn514 for the minified version):
I expected the code to print
0
, the length of the slice.Instead, a random value is printed.
Version it worked on
It most recently worked on:
rustc --version --verbose
:Version with regression
rustc --version --verbose
:@rustbot modify labels: +regression-from-nightly-to-nightly -regression-untriaged
The text was updated successfully, but these errors were encountered: