Skip to content

segfault on Rust 1.97.0 #159035

Description

@yonipeleg33

View all comments

I tried this code:

use std::hint::black_box;
enum Inner { A(u32), B(u32) }
struct Big { _pad: u64, inner: Inner }
struct Small { a: u16, b: u16, _f: fn() }
enum Checksum { X(Big), Y(Small) }
impl Checksum {
    fn finalize(self) -> u32 {
        match self {
            Checksum::X(h) => match h.inner { Inner::A(s) => s, Inner::B(s) => s },
            Checksum::Y(s) => (u32::from(s.b) << 16) | u32::from(s.a),
        }
    }
}
#[inline(never)]
fn run(c: Option<Checksum>) -> Option<u32> {
    c.map(|c| c.finalize())
}
fn main() { println!("{:?}", run(black_box(None))); }

Command:
rustup run <toolchain> rustc -O minimal.rs -o minimal && ./minimal
With toolchain being either 1.97.0 or 1.96.1.

I expected to see this happen: Exit code 0, None printed

Instead, this happened: [1] 112371 segmentation fault (core dumped) ./minimal

Meta

rustc --version --verbose:

rustc --version --verbose
rustc 1.97.0 (2d8144b78 2026-07-07)
binary: rustc
commit-hash: 2d8144b7880597b6e6d3dfd63a9a9efae3f533d3
commit-date: 2026-07-07
host: x86_64-unknown-linux-gnu
release: 1.97.0
LLVM version: 22.1.6

I checked beta (1.98.0) and nightly (1.99.0) - same result

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeO-x86_64Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)P-criticalCritical priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions