Skip to content

Commit fb8b1e3

Browse files
committed
accept undef in raw pointers, for consistency with integers
1 parent 261faf3 commit fb8b1e3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/librustc_mir/interpret/validity.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,16 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>
312312
}
313313
}
314314
ty::RawPtr(..) => {
315-
// No undef allowed here. Eventually this should be consistent with
316-
// the integer types.
317-
let _ptr = try_validation!(value.to_scalar_ptr(),
318-
"undefined address in pointer", self.path);
319-
let _meta = try_validation!(value.to_meta(),
320-
"uninitialized data in fat pointer metadata", self.path);
315+
if self.const_mode {
316+
// Integers/floats in CTFE: For consistency with integers, we do not
317+
// accept undef.
318+
let _ptr = try_validation!(value.to_scalar_ptr(),
319+
"undefined address in raw pointer", self.path);
320+
let _meta = try_validation!(value.to_meta(),
321+
"uninitialized data in raw fat pointer metadata", self.path);
322+
} else {
323+
// Remain consistent with `usize`: Accept anything.
324+
}
321325
}
322326
_ if ty.is_box() || ty.is_region_ptr() => {
323327
// Handle fat pointers.

0 commit comments

Comments
 (0)