-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
ReferencePropagation exposed a latent miscompile, found in the wild with regex #114488
Comments
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-high +T-compiler |
Different example that also starts to miscompile on use std::collections::HashSet;
fn main() {
let maybe_hash_set: Option<HashSet<()>> = None;
for _ in maybe_hash_set.as_ref().unwrap_or(&HashSet::new()) {}
} Interestingly, for this code, only I found this while trying to build Backtrace$ gdb ../tree-sitter/target/release/tree-sitter
(gdb) r generate
[...]
Program received signal SIGSEGV, Segmentation fault.
anyhow::error::vtable (p=...) at src/error.rs:852
852 *(p.as_ptr() as *const &'static ErrorVTable)
(gdb) bt
#0 anyhow::error::vtable (p=...) at src/error.rs:852
#1 0x00005555555d585b in anyhow::Error::downcast_ref<std::io::error::Error> (self=0x7fffffffd5a0)
at src/error.rs:500
#2 tree_sitter::main () at cli/src/main.rs:23
(gdb) Manually reducing the code then yielded the above example. |
Awesome work. I think I know why this bisected to the RefProp PR. I'm trying to do a better bisection... |
While trying to improve the bisection, I have run into an LLVM assertion, so I'm going to work on that and hope that it is the same problem. Update: Looks like this is an unrelated problem with SROA + CopyProp + debuginfo |
Minimized the above reproducer to a small program with no dependencies: https://godbolt.org/z/eeG6soTK1 use std::marker::PhantomData;
struct RawTable<T> {
marker: PhantomData<T>,
}
impl<T> RawTable<T> {
fn iter(&self) -> RawIter<T> {
RawIter {
marker: PhantomData,
}
}
}
struct RawIter<T> {
marker: PhantomData<T>,
}
impl<T> Iterator for RawIter<T> {
type Item = ();
fn next(&mut self) -> Option<()> {
None
}
}
struct HashMap<T> {
table: RawTable<T>,
}
struct Iter<T> {
inner: RawIter<T>, // Removing this breaks the reproducer
}
impl<T> IntoIterator for &HashMap<T> {
type Item = T;
type IntoIter = Iter<T>;
fn into_iter(self) -> Iter<T> {
Iter {
inner: self.table.iter(),
}
}
}
impl<T> Iterator for Iter<T> {
type Item = T;
fn next(&mut self) -> Option<T> {
None
}
}
pub fn main() {
let maybe_hash_set: Option<HashMap<()>> = None;
for _ in maybe_hash_set.as_ref().unwrap_or(&HashMap {
table: RawTable { marker: PhantomData },
}) {}
} Still bisects to the same PR. Note that my minimization relies on having only Inline and ReferencePropagation enabled, so it does not reproduce with stable flags (most likely other MIR opts totally erase this program). But the @rustbot label -requires-nightly -P-high +P-critical |
Input IR: https://godbolt.org/z/GofEbodbo Contains:
This claims uninitialized memory is |
Remove references in VarDebugInfo The codegen implementation is broken, and attempted to read uninitialized memory. Fixes rust-lang/rust#114488
Better reproducer here: #114488 (comment)
I do not have proof that this isn't UB in
regex
but considering how much we have run that crate in Miri I think it is much more likely that this is a miscompilation of some kind.Run with this pile of flags, as far as I can tell they are all required
gdb says the segfault is here:
searched nightlies: from nightly-2023-07-06 to nightly-2023-07-19
regressed nightly: nightly-2023-07-15
searched commit range: 7bd81ee...ad96323
regressed commit: 079e544
bisected with cargo-bisect-rustc v0.6.6
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
cc @cjgillot as the author of #109025
The text was updated successfully, but these errors were encountered: