Skip to content

Commit 4a6ac3c

Browse files
committed
Auto merge of #101647 - crlf0710:test_for_99551, r=bjorn3
Fix LLVM IR type mismatch reported in #99551 Closes #99551 .
2 parents 1463688 + 1cbbd2a commit 4a6ac3c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Diff for: compiler/rustc_codegen_ssa/src/base.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
166166
if let Some(entry_idx) = vptr_entry_idx {
167167
let ptr_ty = cx.type_i8p();
168168
let ptr_align = cx.tcx().data_layout.pointer_align.abi;
169+
let vtable_ptr_ty = cx.scalar_pair_element_backend_type(
170+
cx.layout_of(cx.tcx().mk_mut_ptr(target)),
171+
1,
172+
true,
173+
);
169174
let llvtable = bx.pointercast(old_info, bx.type_ptr_to(ptr_ty));
170175
let gep = bx.inbounds_gep(
171176
ptr_ty,
@@ -176,7 +181,7 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
176181
bx.nonnull_metadata(new_vptr);
177182
// VTable loads are invariant.
178183
bx.set_invariant_load(new_vptr);
179-
new_vptr
184+
bx.pointercast(new_vptr, vtable_ptr_ty)
180185
} else {
181186
old_info
182187
}

Diff for: src/test/ui/codegen/issue-99551.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// build-pass
2+
#![feature(trait_upcasting)]
3+
#![allow(incomplete_features)]
4+
5+
pub trait A {}
6+
pub trait B {}
7+
8+
pub trait C: A + B {}
9+
impl<X: A + B> C for X {}
10+
11+
pub fn test<'a, T>(view: T) -> Option<&'a mut dyn B>
12+
where
13+
T: IntoIterator<Item = &'a mut dyn B>,
14+
{
15+
return Some(view.into_iter().next().unwrap());
16+
}
17+
18+
fn main() {
19+
let mut a: Vec<Box<dyn C>> = Vec::new();
20+
test(a.iter_mut().map(|c| c.as_mut() as &mut dyn B));
21+
}

0 commit comments

Comments
 (0)