about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-10-03 08:59:27 +0200
committerRalf Jung <post@ralfj.de>2018-10-09 13:08:00 +0200
commit22c1a0acc84e8081bc53e3725e0fc944f932aa56 (patch)
tree4677209963c214d8e2bc662c63415f5f90dbdddd
parent9bb4bcd7703366161be2cab416a04077e164aecf (diff)
downloadrust-22c1a0acc84e8081bc53e3725e0fc944f932aa56.tar.gz
rust-22c1a0acc84e8081bc53e3725e0fc944f932aa56.zip
For now, accept all data for integer types when not in const mode
We'll try ruling out undef later
-rw-r--r--src/librustc_mir/interpret/validity.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs
index d7025f9d6b5..219135e3ad8 100644
--- a/src/librustc_mir/interpret/validity.rs
+++ b/src/librustc_mir/interpret/validity.rs
@@ -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.
@@ -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(())