Skip to content

Commit e4e7568

Browse files
authored
Rollup merge of rust-lang#125184 - scottmcm:fix-thin-ptr-ice, r=jieyouxu
Fix ICE in non-operand `aggregate_raw_ptr` intrinsic codegen Introduced in rust-lang#123840 Found in rust-lang#121571, cc `@clarfonthey`
2 parents f9bf759 + f60f2e8 commit e4e7568

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
121121
bx.write_operand_repeatedly(cg_elem, count, dest);
122122
}
123123

124-
mir::Rvalue::Aggregate(ref kind, ref operands) => {
124+
// This implementation does field projection, so never use it for `RawPtr`,
125+
// which will always be fine with the `codegen_rvalue_operand` path below.
126+
mir::Rvalue::Aggregate(ref kind, ref operands)
127+
if !matches!(**kind, mir::AggregateKind::RawPtr(..)) =>
128+
{
125129
let (variant_index, variant_dest, active_field_index) = match **kind {
126130
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
127131
let variant_dest = dest.project_downcast(bx, variant_index);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ compile-flags: -O -C no-prepopulate-passes -Z mir-enable-passes=-InstSimplify
2+
//@ only-64bit (so I don't need to worry about usize)
3+
4+
#![crate_type = "lib"]
5+
#![feature(core_intrinsics)]
6+
7+
use std::intrinsics::aggregate_raw_ptr;
8+
9+
// InstSimplify replaces these with casts if it can, which means they're almost
10+
// never seen in codegen, but PR#121571 found a way, so add a test for it.
11+
12+
#[inline(never)]
13+
pub fn opaque(_p: &*const i32) {}
14+
15+
// CHECK-LABEL: @thin_ptr_via_aggregate(
16+
#[no_mangle]
17+
pub unsafe fn thin_ptr_via_aggregate(p: *const ()) {
18+
// CHECK: %mem = alloca
19+
// CHECK: store ptr %p, ptr %mem
20+
// CHECK: call {{.+}}aggregate_thin_pointer{{.+}} %mem)
21+
let mem = aggregate_raw_ptr(p, ());
22+
opaque(&mem);
23+
}

0 commit comments

Comments
 (0)