Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE in non-operand aggregate_raw_ptr intrinsic codegen #125184

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.write_operand_repeatedly(cg_elem, count, dest);
}

mir::Rvalue::Aggregate(ref kind, ref operands) => {
// This implementation does field projection, so never use it for `RawPtr`,
// which will always be fine with the `codegen_rvalue_operand` path below.
mir::Rvalue::Aggregate(ref kind, ref operands)
if !matches!(**kind, mir::AggregateKind::RawPtr(..)) =>
{
let (variant_index, variant_dest, active_field_index) = match **kind {
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
let variant_dest = dest.project_downcast(bx, variant_index);
Expand Down
23 changes: 23 additions & 0 deletions tests/codegen/intrinsics/aggregate-thin-pointer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//@ compile-flags: -O -C no-prepopulate-passes -Z mir-enable-passes=-InstSimplify
//@ only-64bit (so I don't need to worry about usize)

#![crate_type = "lib"]
#![feature(core_intrinsics)]

use std::intrinsics::aggregate_raw_ptr;

// InstSimplify replaces these with casts if it can, which means they're almost
// never seen in codegen, but PR#121571 found a way, so add a test for it.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ICE demonstration: https://godbolt.org/z/Y7o63MzPn


#[inline(never)]
pub fn opaque(_p: &*const i32) {}

// CHECK-LABEL: @thin_ptr_via_aggregate(
#[no_mangle]
pub unsafe fn thin_ptr_via_aggregate(p: *const ()) {
// CHECK: %mem = alloca
// CHECK: store ptr %p, ptr %mem
// CHECK: call {{.+}}aggregate_thin_pointer{{.+}} %mem)
let mem = aggregate_raw_ptr(p, ());
opaque(&mem);
}
Loading