Skip to content

Better test coverage for AggregateKind::RawPtr #124998

Closed as not planned
Closed as not planned
@scottmcm

Description

@scottmcm

I noticed this today, so making this as a reminder, but if you see it and thing it sounds interesting, please pick it up!

Now that #123886 has landed, the general logic for aggregating immediates ought to work for pointers too, but seemingly it doesn't. We should add tests for whatever the problem is, so that it'll be easier for someone to validate a fix.

Steps:

  1. Delete this block that handles RawPtr specially:

mir::Rvalue::Aggregate(box mir::AggregateKind::RawPtr(..), ref fields) => {
let ty = rvalue.ty(self.mir, self.cx.tcx());
let layout = self.cx.layout_of(self.monomorphize(ty));
let [data, meta] = &*fields.raw else {
bug!("RawPtr fields: {fields:?}");
};
let data = self.codegen_operand(bx, data);
let meta = self.codegen_operand(bx, meta);
match (data.val, meta.val) {
(p @ OperandValue::Immediate(_), OperandValue::ZeroSized) => {
OperandRef { val: p, layout }
}
(OperandValue::Immediate(p), OperandValue::Immediate(m)) => {
OperandRef { val: OperandValue::Pair(p, m), layout }
}
_ => bug!("RawPtr operands {data:?} {meta:?}"),
}
}

  1. Build code to find an ICE. I'm not exactly what code it is, but it might be something related to crossbeam-utils. Might work to just ./x test --stage 2 tests/codegen, since it looks like it failed in the stage2 build in my other PR.

  2. Add minimal code to https://github.com/rust-lang/rust/blob/master/tests/codegen/mir-aggregate-no-alloca.rs that produces the same ICE when running ./x test --stage 1 tests/codegen.

  3. Undo the change from step 1 and add basic validation to the codegen test, similar to that done by the other tests in the file.

  4. Send a PR with the new tests.

  5. (Stretch goal) Delete the block mentioned in step 1 again and fix cg_ssa to pass the new test :D

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions