-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Show the offset, length and memory of uninit read errors #142673
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ use either::{Either, Left, Right}; | |
use rustc_abi as abi; | ||
use rustc_abi::{BackendRepr, HasDataLayout, Size}; | ||
use rustc_hir::def::Namespace; | ||
use rustc_middle::mir::interpret::ScalarSizeMismatch; | ||
use rustc_middle::mir::interpret::{BadBytesAccess, ScalarSizeMismatch}; | ||
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout}; | ||
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter}; | ||
use rustc_middle::ty::{ConstInt, ScalarInt, Ty, TyCtxt}; | ||
|
@@ -663,7 +663,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { | |
} | ||
let imm = self.read_immediate_raw(op)?.right().unwrap(); | ||
if matches!(*imm, Immediate::Uninit) { | ||
throw_ub!(InvalidUninitBytes(None)); | ||
throw_ub!(InvalidUninitBytes(match op.to_op(self)?.as_mplace_or_imm() { | ||
Left(mplace) => mplace.ptr().provenance.and_then(|prov| { | ||
let start = mplace.ptr().into_parts().1; | ||
let size = op.layout().size; | ||
let range = alloc_range(start, size); | ||
Some((prov.get_alloc_id()?, BadBytesAccess { access: range, bad: range })) | ||
}), | ||
Right(_) => None, | ||
})) | ||
Comment on lines
-666
to
+674
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one doesn't show up in diagnostics, but it seemed good to change it, too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why doesn't it show up in diagnostics? Aren't all the miri output diffs caused by exactly this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah no, that diff is probably caused by the If this logic here can't be tested, I'd rather remove it, given that it is currently wrong due to how it uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #142839 gets rid of it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh right, I mixed up things. hmm. yea I think I just tried this one because I thought it should be hit somewhere. So I'll turn it into a span_bug |
||
} | ||
interp_ok(imm) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct -- depending on which type of provenance this is,
start
will be either relative to the allocation, or absolute.into_parts
has a doc comment warning about this. :) Maybe we should rename itinto_raw_parts
or so to make it more clear that this API is somewhat dicey.