Repository navigation
[ICE][miscompile] segv with combined atomic operation and nonnull pointer arithmetic in incremental build #123695
Description
Activity
- addedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Apr 9, 2024 may be running into #123234
This started on stable in 1.73, and bisects to
nightly-2023-08-09:- Use the correct
llvm-profdatabinary inopt-dist#114344 - Update to LLVM 17 #114048
- Rollup of 7 pull requests #114604
- rustc_interface: Dismantle
register_pluginsquery #114578 - simplify handling of valtrees for unsized types #114520
- [rustc_data_structures][base_n][perf] Remove unnecessary utf8 check. #114339
- Map RPIT duplicated lifetimes back to fn captured lifetimes #114602
- Add hotness data to LLVM remarks #114439
- correctly lower
impl constto bind to host effect param #114545
A couple notes, when using cargo:
- incremental compilation is not enabled on release builds
- for people who opt into optimizing dependencies even in debug builds: incremental compilation is not enabled for dependencies either, only local crates
It would be interesting to see exactly what impacts codegen here when enabling incremental compilation of a single session (but at the same time, it seems probable that not many users should encounter this issue in the more common configurations?).
Reacted by Schrodinger ZHU Yifan and QuarticCat- Use the correct
- addedA-codegenArea: Code generationArea: Code generationT-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.A-incr-compArea: Incremental compilationArea: Incremental compilationE-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Exampleand removedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Apr 15, 2024 - added a commit that references this issue
on Apr 16, 2024 - added a commit that references this issue
on Apr 16, 2024 Some additional context: the code is largely related to ecow.
In case people compile typst/ecow related code with incremental build and level 1 optimization enabled and run into segmentation fault, this should be the bug behind it.
So the error happens just from adding
-Cincremental=./inc', without there actually being a previous incremental cache there? Wow.Cc @rust-lang/wg-incr-comp
Seems likely that the LLVM 17 update is involved. Cc @nikic
So the error happens just from adding -Cincremental=./inc', without there actually being a previous incremental cache there?
I can confirm that this reproduces with an empty cache -- which should be good news in terms of debugging the issue.
I'm pretty sure this is a ThinLTO-related bug and incremental somehow configures CGUs and LLVM settings in a way that triggers the bug. The segfault does not reproduce when compiling with
-Copt-level=2 -Cincremental=./inc -Clto=off.Running the miscompiled binary in gdb (with
-Cdebuginfo=2) gives:Program received signal SIGSEGV, Segmentation fault. main::main () at main.rs:52 52 drop(EcoVec::<Foo>::new());
$ llvm-dis < bug.307i3fz7peiqe4ag.rcgu.bc [...] define internal void @_ZN3bug4main17h08d7a889ae812856E() unnamed_addr #0 personality ptr @rust_eh_personality { %1 = atomicrmw sub ptr null, i64 1 release, align 8, !noalias !5 ret void }Yeah, that would crash...
I think this is a minimal reproducer: https://llvm.godbolt.org/z/49Kbq15xn
define ptr @test(ptr nonnull %arg) { %res = getelementptr i8, ptr %arg, i64 -8 ret ptr %res }We infer that the result of this function is nonnull...
- addedA-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.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
on May 6, 2024 - addedI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
on May 6, 2024 Upstream issue: llvm/llvm-project#91177
Reacted by apiraino and dianqkWG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-high
- addedP-highHigh priorityHigh priorityand removedI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
on May 7, 2024 - addedllvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesIssue expected to be fixed by the next major LLVM upgrade, or backported fixes
on May 13, 2024 - added a commit that references this issue
on May 20, 2024
This bug is spotted jointly by @oxalica @Enter-tainer and @QuarticCat.
We tried this code (minimized by @QuarticCat and @oxalica):
I expected to see this happen: The program should exit without error.
Instead, this happened: segmentation fault.
cargo miri run. (miri 0.1.0 (9d5cdf7 2024-04-07)).opt-levellarger than0.incrementalrelated, asrustc -Copt-level=3 bug.rs -o bugdoes not reproduce the bug.cargo asmproduces different asm compared with the one in the ELF output.incdirectory can help):Meta
Both nightly and stable versions are affected
rustc --version --verbose: