Skip to content

Commit 4e1155f

Browse files
committed
Sync from rust 2f320a2
2 parents d7fc563 + 745193d commit 4e1155f

File tree

6 files changed

+48
-24
lines changed

6 files changed

+48
-24
lines changed

Cargo.lock

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gimli = { version = "0.26.0", default-features = false, features = ["write"]}
1919
object = { version = "0.28.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
2020

2121
ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" }
22-
indexmap = "1.8.0"
22+
indexmap = "1.9.1"
2323
libloading = { version = "0.6.0", optional = true }
2424
once_cell = "1.10.0"
2525
smallvec = "1.8.1"

src/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,6 @@ pub(crate) fn codegen_place<'tcx>(
844844
PlaceElem::Deref => {
845845
cplace = cplace.place_deref(fx);
846846
}
847-
PlaceElem::OpaqueCast(ty) => cplace = cplace.place_opaque_cast(fx, ty),
848847
PlaceElem::Field(field, _ty) => {
849848
cplace = cplace.place_field(fx, field);
850849
}

src/constant.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,8 @@ pub(crate) fn codegen_const_value<'tcx>(
195195
}
196196
Scalar::Ptr(ptr, _size) => {
197197
let (alloc_id, offset) = ptr.into_parts(); // we know the `offset` is relative
198-
let alloc_kind = fx.tcx.get_global_alloc(alloc_id);
199-
let base_addr = match alloc_kind {
200-
Some(GlobalAlloc::Memory(alloc)) => {
198+
let base_addr = match fx.tcx.global_alloc(alloc_id) {
199+
GlobalAlloc::Memory(alloc) => {
201200
let data_id = data_id_for_alloc_id(
202201
&mut fx.constants_cx,
203202
fx.module,
@@ -211,13 +210,27 @@ pub(crate) fn codegen_const_value<'tcx>(
211210
}
212211
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
213212
}
214-
Some(GlobalAlloc::Function(instance)) => {
213+
GlobalAlloc::Function(instance) => {
215214
let func_id = crate::abi::import_function(fx.tcx, fx.module, instance);
216215
let local_func_id =
217216
fx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
218217
fx.bcx.ins().func_addr(fx.pointer_type, local_func_id)
219218
}
220-
Some(GlobalAlloc::Static(def_id)) => {
219+
GlobalAlloc::VTable(ty, trait_ref) => {
220+
let alloc_id = fx.tcx.vtable_allocation((ty, trait_ref));
221+
let alloc = fx.tcx.global_alloc(alloc_id).unwrap_memory();
222+
// FIXME: factor this common code with the `Memory` arm into a function?
223+
let data_id = data_id_for_alloc_id(
224+
&mut fx.constants_cx,
225+
fx.module,
226+
alloc_id,
227+
alloc.inner().mutability,
228+
);
229+
let local_data_id =
230+
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
231+
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
232+
}
233+
GlobalAlloc::Static(def_id) => {
221234
assert!(fx.tcx.is_static(def_id));
222235
let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false);
223236
let local_data_id =
@@ -227,7 +240,6 @@ pub(crate) fn codegen_const_value<'tcx>(
227240
}
228241
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
229242
}
230-
None => bug!("missing allocation {:?}", alloc_id),
231243
};
232244
let val = if offset.bytes() != 0 {
233245
fx.bcx.ins().iadd_imm(base_addr, i64::try_from(offset.bytes()).unwrap())
@@ -361,10 +373,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
361373
while let Some(todo_item) = cx.todo.pop() {
362374
let (data_id, alloc, section_name) = match todo_item {
363375
TodoItem::Alloc(alloc_id) => {
364-
//println!("alloc_id {}", alloc_id);
365-
let alloc = match tcx.get_global_alloc(alloc_id).unwrap() {
376+
let alloc = match tcx.global_alloc(alloc_id) {
366377
GlobalAlloc::Memory(alloc) => alloc,
367-
GlobalAlloc::Function(_) | GlobalAlloc::Static(_) => unreachable!(),
378+
GlobalAlloc::Function(_) | GlobalAlloc::Static(_) | GlobalAlloc::VTable(..) => {
379+
unreachable!()
380+
}
368381
};
369382
let data_id = *cx.anon_allocs.entry(alloc_id).or_insert_with(|| {
370383
module
@@ -428,7 +441,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
428441
read_target_uint(endianness, bytes).unwrap()
429442
};
430443

431-
let reloc_target_alloc = tcx.get_global_alloc(alloc_id).unwrap();
444+
let reloc_target_alloc = tcx.global_alloc(alloc_id);
432445
let data_id = match reloc_target_alloc {
433446
GlobalAlloc::Function(instance) => {
434447
assert_eq!(addend, 0);
@@ -441,6 +454,10 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
441454
GlobalAlloc::Memory(target_alloc) => {
442455
data_id_for_alloc_id(cx, module, alloc_id, target_alloc.inner().mutability)
443456
}
457+
GlobalAlloc::VTable(ty, trait_ref) => {
458+
let alloc_id = tcx.vtable_allocation((ty, trait_ref));
459+
data_id_for_alloc_id(cx, module, alloc_id, Mutability::Not)
460+
}
444461
GlobalAlloc::Static(def_id) => {
445462
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)
446463
{

src/intrinsics/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ fn codegen_regular_intrinsic_call<'tcx>(
435435
ret.write_cvalue(fx, CValue::by_val(align, usize_layout));
436436
};
437437

438+
vtable_size, (v vtable) {
439+
let size = crate::vtable::size_of_obj(fx, vtable);
440+
ret.write_cvalue(fx, CValue::by_val(size, usize_layout));
441+
};
442+
443+
vtable_align, (v vtable) {
444+
let align = crate::vtable::min_align_of_obj(fx, vtable);
445+
ret.write_cvalue(fx, CValue::by_val(align, usize_layout));
446+
};
447+
438448
unchecked_add | unchecked_sub | unchecked_mul | unchecked_div | exact_div | unchecked_rem
439449
| unchecked_shl | unchecked_shr, (c x, c y) {
440450
// FIXME trap on overflow

src/value_and_place.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,6 @@ impl<'tcx> CPlace<'tcx> {
621621
}
622622
}
623623

624-
pub(crate) fn place_opaque_cast(
625-
self,
626-
fx: &mut FunctionCx<'_, '_, 'tcx>,
627-
ty: Ty<'tcx>,
628-
) -> CPlace<'tcx> {
629-
CPlace { inner: self.inner, layout: fx.layout_of(ty) }
630-
}
631-
632624
pub(crate) fn place_field(
633625
self,
634626
fx: &mut FunctionCx<'_, '_, 'tcx>,

0 commit comments

Comments
 (0)