From 6048adc8b1cc5db39af736cf4531c46059b6966d Mon Sep 17 00:00:00 2001 From: Smitty Date: Sat, 12 Jun 2021 19:49:48 -0400 Subject: [PATCH 1/4] Support allocation failures when interperting MIR Note that this breaks Miri. Closes #79601 --- src/vtable.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vtable.rs b/src/vtable.rs index 12f7092d935..5788aabaadc 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -72,7 +72,10 @@ pub(crate) fn get_vtable<'tcx>( let vtable_ptr = if let Some(vtable_ptr) = fx.vtables.get(&(ty, trait_ref)) { *vtable_ptr } else { - let vtable_alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); + let vtable_alloc_id = match fx.tcx.vtable_allocation(ty, trait_ref) { + Ok(alloc) => alloc, + Err(_) => fx.tcx.sess().fatal("allocation of constant vtable failed"), + }; let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory(); let vtable_ptr = pointer_for_allocation(fx, vtable_allocation); From 17373a94018ee37365cc1c1c48e88372bb7c4283 Mon Sep 17 00:00:00 2001 From: Smitty Date: Tue, 29 Jun 2021 19:17:14 -0400 Subject: [PATCH 2/4] fix sess error This passed x.py check locally, not sure why it wasn't rebased right... --- src/vtable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vtable.rs b/src/vtable.rs index 5788aabaadc..7ee34b23e46 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -74,7 +74,7 @@ pub(crate) fn get_vtable<'tcx>( } else { let vtable_alloc_id = match fx.tcx.vtable_allocation(ty, trait_ref) { Ok(alloc) => alloc, - Err(_) => fx.tcx.sess().fatal("allocation of constant vtable failed"), + Err(_) => fx.tcx.sess.fatal("allocation of constant vtable failed"), }; let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory(); let vtable_ptr = pointer_for_allocation(fx, vtable_allocation); From 913c0bc01dbab632d1512f703c026aac7acfa197 Mon Sep 17 00:00:00 2001 From: Smitty Date: Sat, 3 Jul 2021 11:14:19 -0400 Subject: [PATCH 3/4] Make vtable_allocation always succeed --- src/vtable.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/vtable.rs b/src/vtable.rs index 7ee34b23e46..12f7092d935 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -72,10 +72,7 @@ pub(crate) fn get_vtable<'tcx>( let vtable_ptr = if let Some(vtable_ptr) = fx.vtables.get(&(ty, trait_ref)) { *vtable_ptr } else { - let vtable_alloc_id = match fx.tcx.vtable_allocation(ty, trait_ref) { - Ok(alloc) => alloc, - Err(_) => fx.tcx.sess.fatal("allocation of constant vtable failed"), - }; + let vtable_alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory(); let vtable_ptr = pointer_for_allocation(fx, vtable_allocation); From 6b3a061e947fcb928b94cd5a7db3bdfd225f87b4 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 7 Jun 2021 12:18:28 +0200 Subject: [PATCH 4/4] Remove LibSource The information is stored in used_crate_source too anyway --- src/driver/jit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 4a99cb727c8..3f96e741d35 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -185,7 +185,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> { .find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable) .unwrap() .1; - for &(cnum, _) in &crate_info.used_crates_dynamic { + for &cnum in &crate_info.used_crates { let src = &crate_info.used_crate_source[&cnum]; match data[cnum.as_usize() - 1] { Linkage::NotLinked | Linkage::IncludedFromDylib => {}