Skip to content

Commit

Permalink
For now, accept all data for integer types when not in const mode
Browse files Browse the repository at this point in the history
We'll try ruling out undef later
  • Loading branch information
RalfJung committed Oct 3, 2018
1 parent 5eab6f1 commit 7826d97
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,18 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
scalar_format(value), path, "a valid unicode codepoint");
},
ty::Float(_) | ty::Int(_) | ty::Uint(_) if const_mode => {
// Integers/floats in CTFE: Must be scalar bits
// Integers/floats in CTFE: Must be scalar bits, pointers are dangerous
try_validation!(value.to_bits(size),
scalar_format(value), path, "initialized plain bits");
}
ty::Float(_) | ty::Int(_) | ty::Uint(_) | ty::RawPtr(_) => {
// Anything but undef goes
try_validation!(value.not_undef(),
scalar_format(value), path, "a raw pointer");
if const_mode {
// Anything but undef goes
try_validation!(value.not_undef(),
scalar_format(value), path, "a raw pointer");
} else {
// At run-time, for now, we accept *anything* for these types.
}
},
ty::Ref(..) => {
// This is checked by the recursive reference handling, nothing to do here.
Expand All @@ -182,10 +186,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
scalar_format(value), path, "a function pointer");
// FIXME: Check if the signature matches
}
ty::FnDef(..) => {
// This is a zero-sized type with all relevant data sitting in the type.
// There is nothing to validate.
}
// This should be all
ty::Never => bug!("Uninhabited type should have been catched earlier"),
_ => bug!("Unexpected primitive type {}", ty)
}
Ok(())
Expand Down

0 comments on commit 7826d97

Please sign in to comment.