Skip to content

Miscompilation with -Zsanitizer=address #120260

Closed
@fintelia

Description

@fintelia
Contributor

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

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 23, 2024
added
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
A-sanitizersArea: Sanitizers for correctness and code quality
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 23, 2024
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jan 23, 2024
nikic

nikic commented on Jan 23, 2024

@nikic
Contributor

Also reproduces without -Z build-std. I also tested this with +b10e3758cdf73aa9155f6b955843731a66488b9c, so it doesn't look like this issue has been fixed in LLVM 18.

nikic

nikic commented on Jan 23, 2024

@nikic
Contributor

opt-bisect points to:

BISECT: NOT running pass (2036) LoopVectorizePass on _ZN3foo8unfilter17hcdf00299b79e44ccE

IR for this function without and with LoopVectorize: https://gist.github.com/nikic/619764c58f3cd184326ffdd6831abc2e

nikic

nikic commented on Jan 23, 2024

@nikic
Contributor

Upstream issue: llvm/llvm-project#79137

self-assigned this
on Jan 23, 2024
apiraino

apiraino commented on Jan 23, 2024

@apiraino
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high

added
P-highHigh priority
and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jan 23, 2024

6 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @nikic@fintelia@apiraino@rustbot@tmiasko

      Issue actions

        Miscompilation with -Zsanitizer=address · Issue #120260 · rust-lang/rust