]> git.lizzy.rs Git - rust.git/commitdiff
Fix mozjs crater failure
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 20 Feb 2018 10:49:50 +0000 (11:49 +0100)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 8 Mar 2018 07:34:18 +0000 (08:34 +0100)
src/librustc_mir/interpret/eval_context.rs
src/test/run-pass/ctfe/mozjs-error.rs [new file with mode: 0644]

index 64e823564671b22762f49ae84ff9a32b9a9d1ec3..e0ad306571d249c515f47c5bf16c65d6433d30bf 100644 (file)
@@ -246,7 +246,10 @@ pub(super) fn const_to_value(&self, const_val: &ConstVal<'tcx>, ty: Ty<'tcx>) ->
     }
 
     pub(super) fn resolve(&self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> EvalResult<'tcx, ty::Instance<'tcx>> {
-        let substs = self.tcx.trans_apply_param_substs(self.substs(), &substs);
+        trace!("resolve: {:?}, {:#?}", def_id, substs);
+        trace!("substs: {:#?}", self.substs());
+        trace!("param_env: {:#?}", self.param_env);
+        let substs = self.tcx.trans_apply_param_substs_env(self.substs(), self.param_env, &substs);
         ty::Instance::resolve(
             *self.tcx,
             self.param_env,
@@ -690,8 +693,13 @@ pub(super) fn eval_rvalue_into_place(
                                     bug!("reifying a fn ptr that requires \
                                           const arguments");
                                 }
-                                let instance = self.resolve(def_id, substs)?;
-                                let fn_ptr = self.memory.create_fn_alloc(instance);
+                                let instance: EvalResult<'tcx, _> = ty::Instance::resolve(
+                                    *self.tcx,
+                                    self.param_env,
+                                    def_id,
+                                    substs,
+                                ).ok_or(EvalErrorKind::TypeckError.into());
+                                let fn_ptr = self.memory.create_fn_alloc(instance?);
                                 let valty = ValTy {
                                     value: Value::ByVal(PrimVal::Ptr(fn_ptr)),
                                     ty: dest_ty,
diff --git a/src/test/run-pass/ctfe/mozjs-error.rs b/src/test/run-pass/ctfe/mozjs-error.rs
new file mode 100644 (file)
index 0000000..9c8a4b5
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+struct CustomAutoRooterVFTable {
+    trace: unsafe extern "C" fn(this: *mut i32, trc: *mut u32),
+}
+
+unsafe trait CustomAutoTraceable: Sized {
+    const vftable: CustomAutoRooterVFTable = CustomAutoRooterVFTable {
+        trace: Self::trace,
+    };
+
+    unsafe extern "C" fn trace(this: *mut i32, trc: *mut u32) {
+        let this = this as *const Self;
+        let this = this.as_ref().unwrap();
+        Self::do_trace(this, trc);
+    }
+
+    fn do_trace(&self, trc: *mut u32);
+}
+
+unsafe impl CustomAutoTraceable for () {
+    fn do_trace(&self, _: *mut u32) {
+        // nop
+    }
+}
+
+fn main() {
+    let _ = <()>::vftable;
+}