File tree Expand file tree Collapse file tree 2 files changed +5
-0
lines changed Expand file tree Collapse file tree 2 files changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -349,6 +349,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
349
349
350
350
if !tracing {
351
351
// Expose all provenances in this allocation, since the native code can do $whatever.
352
+ // Can be skipped when tracing; in that case we'll expose just the actually-read parts later.
352
353
for prov in alloc. provenance ( ) . provenances ( ) {
353
354
this. expose_provenance ( prov) ?;
354
355
}
@@ -357,6 +358,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
357
358
// Prepare for possible write from native code if mutable.
358
359
if info. mutbl . is_mut ( ) {
359
360
let ( alloc, cx) = this. get_alloc_raw_mut ( alloc_id) ?;
361
+ // These writes could initialize everything and wreck havoc with the pointers.
362
+ // We can skip that when tracing; in that case we'll later do that only for the memory that got actually written.
360
363
if !tracing {
361
364
alloc. process_native_write ( & cx. tcx , None ) ;
362
365
}
Original file line number Diff line number Diff line change @@ -16,9 +16,11 @@ fn partial_init() {
16
16
let mut slice = std:: mem:: MaybeUninit :: < [ u8 ; 3 ] > :: uninit ( ) ;
17
17
let slice_ptr = slice. as_mut_ptr ( ) . cast :: < u8 > ( ) ;
18
18
unsafe {
19
+ // Initialize the first two elements.
19
20
init_n ( 2 , slice_ptr) ;
20
21
assert ! ( * slice_ptr == 0 ) ;
21
22
assert ! ( * slice_ptr. offset( 1 ) == 0 ) ;
23
+ // Reading the third is UB!
22
24
let _val = * slice_ptr. offset ( 2 ) ; //~ ERROR: Undefined Behavior: using uninitialized data
23
25
}
24
26
}
You can’t perform that action at this time.
0 commit comments