Skip to content

Commit 938f852

Browse files
committed
miri validation: debug-complain about unexpected errors
1 parent 0468929 commit 938f852

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/librustc_mir/interpret/validity.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ macro_rules! try_validation {
4646
($e:expr, $what:expr, $where:expr, $details:expr) => {{
4747
match $e {
4848
Ok(x) => x,
49+
// We re-throw the error, so we are okay with allocation:
50+
// this can only slow down builds that fail anyway.
4951
Err(_) => throw_validation_failure!($what, $where, $details),
5052
}
5153
}};
5254

5355
($e:expr, $what:expr, $where:expr) => {{
5456
match $e {
5557
Ok(x) => x,
58+
// We re-throw the error, so we are okay with allocation:
59+
// this can only slow down builds that fail anyway.
5660
Err(_) => throw_validation_failure!($what, $where),
5761
}
5862
}};
@@ -359,10 +363,13 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
359363
format_args!("a dangling {} (created from integer)", kind),
360364
self.path
361365
),
362-
_ => throw_validation_failure!(
363-
format_args!("a dangling {} (not entirely in bounds)", kind),
364-
self.path
365-
),
366+
err_unsup!(PointerOutOfBounds { .. }) | err_unsup!(DanglingPointerDeref) => {
367+
throw_validation_failure!(
368+
format_args!("a dangling {} (not entirely in bounds)", kind),
369+
self.path
370+
)
371+
}
372+
_ => bug!("Unexpected error during ptr inbounds test: {}", err),
366373
}
367374
}
368375
};
@@ -638,6 +645,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
638645
err_unsup!(ReadPointerAsBytes) => {
639646
throw_validation_failure!("a pointer", self.path, "plain (non-pointer) bytes")
640647
}
648+
// Propagate upwards (that will also check for unexpected errors).
641649
_ => return Err(err),
642650
},
643651
}
@@ -797,7 +805,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
797805
// Try to cast to ptr *once* instead of all the time.
798806
let op = self.force_op_ptr(op).unwrap_or(op);
799807

800-
// Run it
801-
visitor.visit_value(op)
808+
// Run it.
809+
match visitor.visit_value(op) {
810+
Ok(()) => Ok(()),
811+
Err(err) if matches!(err.kind, err_unsup!(ValidationFailure { .. })) => Err(err),
812+
Err(err) if cfg!(debug_assertions) => {
813+
bug!("Unexpected error during validation: {}", err)
814+
}
815+
Err(err) => Err(err),
816+
}
802817
}
803818
}

0 commit comments

Comments
 (0)