Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscompilation with -Zsanitizer=address #120260

Closed
fintelia opened this issue Jan 23, 2024 · 6 comments
Closed

Miscompilation with -Zsanitizer=address #120260

fintelia opened this issue Jan 23, 2024 · 6 comments
Assignees
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-sanitizers Area: Sanitizers for correctness and code quality C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fintelia
Copy link
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
@fintelia fintelia added the C-bug Category: This is a bug. label Jan 23, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 23, 2024
@tmiasko tmiasko added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness A-sanitizers Area: Sanitizers for correctness and code quality and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 23, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 23, 2024
@nikic
Copy link
Contributor

nikic commented Jan 23, 2024

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
Copy link
Contributor

nikic commented Jan 23, 2024

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
Copy link
Contributor

nikic commented Jan 23, 2024

Upstream issue: llvm/llvm-project#79137

@nikic nikic self-assigned this Jan 23, 2024
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 23, 2024
@nikic nikic added the llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes label Jan 24, 2024
@nikic
Copy link
Contributor

nikic commented Jan 24, 2024

Fixed upstream by llvm/llvm-project@cd7ea4e.

@nikic
Copy link
Contributor

nikic commented Feb 16, 2024

Fixed in beta & nightly.

@nikic nikic closed this as completed Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-sanitizers Area: Sanitizers for correctness and code quality C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants