Skip to content

Commit

Permalink
Auto merge of #101647 - crlf0710:test_for_99551, r=bjorn3
Browse files Browse the repository at this point in the history
Fix LLVM IR type mismatch reported in #99551

Closes #99551 .
  • Loading branch information
bors committed Sep 10, 2022
2 parents 1463688 + 1cbbd2a commit 4a6ac3c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
if let Some(entry_idx) = vptr_entry_idx {
let ptr_ty = cx.type_i8p();
let ptr_align = cx.tcx().data_layout.pointer_align.abi;
let vtable_ptr_ty = cx.scalar_pair_element_backend_type(
cx.layout_of(cx.tcx().mk_mut_ptr(target)),
1,
true,
);
let llvtable = bx.pointercast(old_info, bx.type_ptr_to(ptr_ty));
let gep = bx.inbounds_gep(
ptr_ty,
Expand All @@ -176,7 +181,7 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
bx.nonnull_metadata(new_vptr);
// VTable loads are invariant.
bx.set_invariant_load(new_vptr);
new_vptr
bx.pointercast(new_vptr, vtable_ptr_ty)
} else {
old_info
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/codegen/issue-99551.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// build-pass
#![feature(trait_upcasting)]
#![allow(incomplete_features)]

pub trait A {}
pub trait B {}

pub trait C: A + B {}
impl<X: A + B> C for X {}

pub fn test<'a, T>(view: T) -> Option<&'a mut dyn B>
where
T: IntoIterator<Item = &'a mut dyn B>,
{
return Some(view.into_iter().next().unwrap());
}

fn main() {
let mut a: Vec<Box<dyn C>> = Vec::new();
test(a.iter_mut().map(|c| c.as_mut() as &mut dyn B));
}

0 comments on commit 4a6ac3c

Please sign in to comment.