-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-rustlantisA miscompilation found by RustlantisA miscompilation found by RustlantisC-bugCategory: This is a bug.Category: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I think this is an LLVM SROA bug, it reproduces with -Cno-prepopulate-passes -Cpasses=sroa.
I'm running out of ideas for how to minimize this. Maybe it's minimal?
#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;
#[inline(never)]
fn opaque<T>(t: T) {std::hint::black_box(t);}
#[inline(never)]
#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn fn0() -> ([u8; 1], u32) {
mir! {
let _1: (([u8; 1], u32), [u8; 5]);
let _2: ();
{
_1.0.0 = [0];
_1.0.1 = 2;
_1.1 = [0, 0, 0, 0, 0];
Call(RET = fn1(_1.0, _1.0, _1), ReturnTo(bb2), UnwindUnreachable())
}
bb2 = {
Call(_2 = opaque(Move(_1)), ReturnTo(bb3), UnwindUnreachable())
}
bb3 = {
Return()
}
}
}
#[inline(never)]
#[custom_mir(dialect = "runtime", phase = "initial")]
fn fn1(
mut _1: ([u8; 1], u32),
mut _2: ([u8; 1], u32),
mut _3: (([u8; 1], u32), [u8; 5]),
) -> ([u8; 1], u32) {
mir! {
let _4: ();
{
_1 = (_3.0.0, 0);
_3.0 = _1;
RET = _1;
Call(_4 = opaque(_2.1), ReturnTo(bb6), UnwindUnreachable())
}
bb6 = {
Call(_4 = opaque(Move(_3)), ReturnTo(bb7), UnwindUnreachable())
}
bb7 = {
Return()
}
}
}
fn main() {
println!("{:?}", fn0());
}Miri prints:
([0], 0)
rustc -Copt-level=1 -Zmir-opt-level=0 prints:
([0], 2)
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-rustlantisA miscompilation found by RustlantisA miscompilation found by RustlantisC-bugCategory: This is a bug.Category: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.