Skip to content

Miscompilation with -Zsanitizer=address #120260

Closed
@fintelia

Description

@fintelia

I tried this code:

#[inline(never)]
fn unfilter(current: &mut [u8]) {
    current.iter_mut().reduce(|&mut prev, curr| {
        *curr = curr.wrapping_add(prev);
        curr
    });
}

fn main() {
    let mut data = [255, 0, 18, 243, 13, 240, 255, 0, 4];
    unfilter(&mut data);
    assert_eq!(data, [255, 255, 17, 4, 17, 1, 0, 0, 4]);
}

And compiled with these arguments:

RUSTFLAGS="-Zsanitizer=address -Clink-dead-code -C codegen-units=1" cargo +nightly run -Z build-std --target=x86_64-unknown-linux-gnu --release

I expected to see this happen: assertion passes like it does on the playground or with cargo run.

Instead, this happened:

thread 'main' panicked at src/main.rs:12:5:
assertion `left == right` failed
  left: [255, 255, 18, 5, 0, 253, 239, 255, 4]
 right: [255, 255, 17, 4, 17, 1, 0, 0, 4]

Meta

rustc +nightly --version --verbose:

rustc 1.77.0-nightly (d5fd09972 2024-01-22)
binary: rustc
commit-hash: d5fd0997291ca0135401a39dff25c8a9c13b8961
commit-date: 2024-01-22
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-sanitizersArea: Sanitizers for correctness and code qualityC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh 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 fixes

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions