Skip to content

Rust 1.60 segmentation fault related to const generics #96672

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

Closed
NickHu opened this issue May 3, 2022 · 11 comments · Fixed by #96966
Closed

Rust 1.60 segmentation fault related to const generics #96672

NickHu opened this issue May 3, 2022 · 11 comments · Fixed by #96966
Assignees
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another.

Comments

@NickHu
Copy link

NickHu commented May 3, 2022

Code

I tried this code:

nix build github:homotopy-io/homotopy-rs?rev=0cc608109c699f7fac2e7979f2f0d440ac4ac786

I expected to see this happen: successful compilation

Instead, this happened:

@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/v4fmilsv73fjm9gy6ggvdlkds4m8a9af-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
[naersk] cargo_version (read): 1.60.0 (d1fd9fe 2022-03-01)
[naersk] cargo_message_format (set): json-diagnostic-rendered-ansi
[naersk] cargo_release: --release
[naersk] cargo_options: 
[naersk] cargo_build_options: $cargo_release -j "$NIX_BUILD_CORES" --message-format=$cargo_message_format -p homotopy-web
[naersk] cargo_test_options: $cargo_release -j "$NIX_BUILD_CORES"
[naersk] RUST_TEST_THREADS: 32
[naersk] cargo_bins_jq_filter: select(.reason == "compiler-artifact" and .executable != null and .profile.test == false)
[naersk] cargo_build_output_json (created): /build/tmp.AMfM0fmYyn
[naersk] crate_sources: /nix/store/hjmyjcasiifgnpm0s0ss264ry3100iq8-crates-io
[naersk] RUSTFLAGS: 
[naersk] CARGO_BUILD_RUSTFLAGS: 
[naersk] CARGO_BUILD_RUSTFLAGS (updated): --remap-path-prefix /nix/store/hjmyjcasiifgnpm0s0ss264ry3100iq8-crates-io=/sources
[naersk] pre-installing dep /nix/store/4risald0r359aliark65q2fmhif5ml0j-homotopy-web-deps-0.1.2
@nix { "action": "setPhase", "phase": "buildPhase" }
building
cargo build $cargo_release -j "$NIX_BUILD_CORES" --message-format=$cargo_message_format -p homotopy-web
�[0m�[0m�[1m�[32m   Compiling�[0m homotopy-common v0.1.0 (/build/source/homotopy-common)
�[0m�[0m�[1m�[32m   Compiling�[0m homotopy-core v0.1.0 (/build/source/homotopy-core)
�[0m�[0m�[1m�[32m   Compiling�[0m homotopy-graphics v0.1.0 (/build/source/homotopy-graphics)
�[0m�[0m�[1m�[32m   Compiling�[0m homotopy-web v0.1.2 (/build/source/homotopy-web)
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x4b3d23)[0x7ffff469bd23]
/nix/store/ayrsyv7npr0lcbann4k9lxr19x813f0z-glibc-2.34-115/lib/libc.so.6(+0x41100)[0x7ffff3cab100]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(_ZN4llvm10BasicBlockC1ERNS_11LLVMContextERKNS_5TwineEPNS_8FunctionEPS0_+0xc5)[0x7ffff132a075]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x2707510)[0x7ffff0f23510]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x27008af)[0x7ffff0f1c8af]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(_ZN4llvm11simplifyCFGEPNS_10BasicBlockERKNS_19TargetTransformInfoEPNS_14DomTreeUpdaterERKNS_18SimplifyCFGOptionsENS_8ArrayRefINS_6WeakVHEEE+0x2315)[0x7ffff0ed8965]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x26b7bc5)[0x7ffff0ed3bc5]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x26b529a)[0x7ffff0ed129a]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x2387229)[0x7ffff0ba3229]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(_ZN4llvm27ModuleToFunctionPassAdaptor3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0x329)[0x7ffff1aa7659]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(+0x328b31d)[0x7ffff1aa731d]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libLLVM-14-rust-1.60.0-stable.so(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x144)[0x7ffff19285c4]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x23dfef1)[0x7ffff65c7ef1]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x23cdb54)[0x7ffff65b5b54]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x23ce0a1)[0x7ffff65b60a1]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x2365d7d)[0x7ffff654dd7d]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x238380f)[0x7ffff656b80f]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/librustc_driver-75e5f32fc3580f6c.so(+0x2372bc7)[0x7ffff655abc7]
/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/lib/libstd-8d61b92a0a02f53a.so(rust_metadata_std_cd3cf6af28dff6de+0xa7d03)[0x7ffff3f21d03]
/nix/store/ayrsyv7npr0lcbann4k9lxr19x813f0z-glibc-2.34-115/lib/libc.so.6(+0x89eb2)[0x7ffff3cf3eb2]
/nix/store/ayrsyv7npr0lcbann4k9lxr19x813f0z-glibc-2.34-115/lib/libc.so.6(+0x10c31c)[0x7ffff3d7631c]
�[0m�[0m�[1m�[31merror�[0m�[1m:�[0m could not compile `homotopy-web`

Caused by:
  process didn't exit successfully: `/nix/store/v1kdj5bb8pp5bb3pk23s96nfbfpic6f0-rust-minimal-1.60.0/bin/rustc --crate-name homotopy_web --edition=2021 homotopy-web/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type cdylib --crate-type rlib --emit=dep-info,link -C opt-level=3 --cfg 'feature="console_error_panic_hook"' --cfg 'feature="default"' -C metadata=d0edfb7c13dcde66 --out-dir /build/source/target/wasm32-unknown-unknown/release/deps --target wasm32-unknown-unknown -L dependency=/build/source/target/wasm32-unknown-unknown/release/deps -L dependency=/build/source/target/release/deps --extern arrayvec=/build/source/target/wasm32-unknown-unknown/release/deps/libarrayvec-064facd1d3b4ac08.rlib --extern closure=/build/source/target/wasm32-unknown-unknown/release/deps/libclosure-22ef8d2fe5957b87.rlib --extern console_error_panic_hook=/build/source/target/wasm32-unknown-unknown/release/deps/libconsole_error_panic_hook-2057c4514695902f.rlib --extern euclid=/build/source/target/wasm32-unknown-unknown/release/deps/libeuclid-3dae85bc5bb07a71.rlib --extern gloo=/build/source/target/wasm32-unknown-unknown/release/deps/libgloo-b43aad26b340de48.rlib --extern gloo_timers=/build/source/target/wasm32-unknown-unknown/release/deps/libgloo_timers-bc23fdea00850d70.rlib --extern homotopy_common=/build/source/target/wasm32-unknown-unknown/release/deps/libhomotopy_common-0ba795d2fc24788e.rlib --extern homotopy_core=/build/source/target/wasm32-unknown-unknown/release/deps/libhomotopy_core-5b86ed58e29945d8.rlib --extern homotopy_graphics=/build/source/target/wasm32-unknown-unknown/release/deps/libhomotopy_graphics-5b9942fcbc1b42fd.rlib --extern im=/build/source/target/wasm32-unknown-unknown/release/deps/libim-f68605f388142b72.rlib --extern instant=/build/source/target/wasm32-unknown-unknown/release/deps/libinstant-15f531c8d8e23534.rlib --extern js_sys=/build/source/target/wasm32-unknown-unknown/release/deps/libjs_sys-d892199c945c5dfe.rlib --extern log=/build/source/target/wasm32-unknown-unknown/release/deps/liblog-f0424ddc1a3d06f8.rlib --extern lyon_path=/build/source/target/wasm32-unknown-unknown/release/deps/liblyon_path-4c1b5b611b75ca6b.rlib --extern obake=/build/source/target/wasm32-unknown-unknown/release/deps/libobake-5427d7eb3090cf45.rlib --extern palette=/build/source/target/wasm32-unknown-unknown/release/deps/libpalette-087ea92923972b9c.rlib --extern paste=/build/source/target/release/deps/libpaste-9f4ba831280a7332.so --extern quote=/build/source/target/wasm32-unknown-unknown/release/deps/libquote-0bea2f79134eb277.rlib --extern rmp_serde=/build/source/target/wasm32-unknown-unknown/release/deps/librmp_serde-104a28574bf452c8.rlib --extern serde=/build/source/target/wasm32-unknown-unknown/release/deps/libserde-8cef68772708519b.rlib --extern syn=/build/source/target/wasm32-unknown-unknown/release/deps/libsyn-fc3acf24a1e49ab3.rlib --extern thiserror=/build/source/target/wasm32-unknown-unknown/release/deps/libthiserror-033ceb9e6bdfab8c.rlib --extern ultraviolet=/build/source/target/wasm32-unknown-unknown/release/deps/libultraviolet-40630f624adb9f9d.rlib --extern wasm_bindgen=/build/source/target/wasm32-unknown-unknown/release/deps/libwasm_bindgen-a75edcdc1a8fc987.rlib --extern wasm_logger=/build/source/target/wasm32-unknown-unknown/release/deps/libwasm_logger-235f2a8f6828be52.rlib --extern web_sys=/build/source/target/wasm32-unknown-unknown/release/deps/libweb_sys-96345e1705e5ba46.rlib --extern yew=/build/source/target/wasm32-unknown-unknown/release/deps/libyew-e97f053b58fd785b.rlib --extern yew_agent=/build/source/target/wasm32-unknown-unknown/release/deps/libyew_agent-af8da546ff0d9932.rlib --extern yew_macro=/build/source/target/release/deps/libyew_macro-967187fef99f778d.so --remap-path-prefix /nix/store/hjmyjcasiifgnpm0s0ss264ry3100iq8-crates-io=/sources` (signal: 11, SIGSEGV: invalid memory reference)
[naersk] cargo returned with exit code 101, exiting

Version it worked on

It most recently worked on (nix build github:homotopy-io/homotopy-rs?rev=5ba852c72a3e552d3668233a14fd9769dea0797e):

rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.0

Version with regression

rustc --version --verbose:

rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-unknown-linux-gnu
release: 1.60.0
LLVM version: 14.0.0

Other information

We've determined that https://github.com/homotopy-io/homotopy-rs/blob/0cc608109c699f7fac2e7979f2f0d440ac4ac786/homotopy-web/src/app/workspace.rs#L101 is the culprit; either removing that line or replacing <0> with <1> both fix the compiler crashing (although this does not produce the code we want).

This looks like it's possibly related to the LLVM version.

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

@NickHu NickHu added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels May 3, 2022
@rustbot rustbot added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed regression-untriaged Untriaged performance or correctness regression. labels May 3, 2022
@apiraino
Copy link
Contributor

apiraino commented May 3, 2022

A bit of reducing could help here. ideally we want to be able to reproduce.

@rustbot label +O-wasm

tagging also
@rustbot ping icebreakers-cleanup-crew

@rustbot rustbot added the O-wasm Target: WASM (WebAssembly), http://webassembly.org/ label May 3, 2022
@rustbot
Copy link
Collaborator

rustbot commented May 3, 2022

Hey Cleanup Crew ICE-breakers! This bug has been identified as a good
"Cleanup ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3

cc @AminArria @ayazhafiz @camelid @chrissimpkins @contrun @elshize @h-michael @HallerPatrick @hdhoang @hellow554 @henryboisdequin @imtsuki @JamesPatrickGill @kanru @KarlK90 @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @shekohex @sinato @smmalis37 @steffahn @Stupremee @tamuhey @turboladen @woshilapin @yerke

@rustbot rustbot added the ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections label May 3, 2022
@SNCPlay42
Copy link
Contributor

Reduced: (must be compiled with --target=wasm32-unknown-unknown -C opt-level=3, which can be done on playground by setting to "release" and clicking "WASM" instead of "Run")

fn explode<V, F, V2>(mut node_map: F) -> Option<()>
where
    F: FnMut(V) -> Option<V2>,
{
    let key = conjure();
    node_map(key)?;
    None
}

pub struct Layout<const N: usize>;
impl<const N: usize> Layout<N> {
    pub fn new() {
        for i in 0..N {
            let node_map = |key: [(); N]| -> Option<[f32; N]> {
                key[i];
                None
            };
            explode(node_map);
        }
    }
}

fn conjure<T>() -> T {
    unimplemented!()
}

pub fn main() {
    Layout::<0>::new();
}

@SNCPlay42
Copy link
Contributor

searched nightlies: from nightly-2022-01-13 to nightly-2022-05-03
regressed nightly: nightly-2022-03-11
searched commit range: 458262b...5f4e067
regressed commit: 282778a

bisected with cargo-bisect-rustc v0.6.3

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --preserve --start=2022-01-13 --target=wasm32-unknown-unknown -- build --release --target=wasm32-unknown-unknown 

This did indeed regress in the LLVM bump (#94764).

@rustbot label I-crash A-llvm

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. labels May 3, 2022
@apiraino
Copy link
Contributor

apiraino commented May 4, 2022

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

Great work @SNCPlay42 thanks!

@rustbot label -I-prioritize +P-high -ICEBreaker-Cleanup-Crew

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections labels May 4, 2022
@luqmana
Copy link
Member

luqmana commented May 6, 2022

Looks like https://reviews.llvm.org/D119854 is the change where it starts failing.
Adding -C llvm-args="-switch-range-to-icmp=1" does seem to work around the crash.

cc @nikic

@nikic
Copy link
Contributor

nikic commented May 6, 2022

IR: https://gist.github.com/nikic/66478e84510d35b763a6b99a2aefa508 Running this through opt -O3 crashes with LLVM 14 but works fine on main, so this was apparently already fixed in the meantime.

@nikic
Copy link
Contributor

nikic commented May 6, 2022

Bisect points to llvm/llvm-project@857c612, which probably just hides the problem.

@nikic
Copy link
Contributor

nikic commented May 6, 2022

Ah no, I misread. That does look like the actual fix for the issue.

@nikic
Copy link
Contributor

nikic commented May 6, 2022

Filed backport issue: llvm/llvm-project#55304

@nikic nikic self-assigned this May 9, 2022
@bors bors closed this as completed in ebb80ec May 13, 2022
@NickHu
Copy link
Author

NickHu commented Jun 16, 2022

Apologies for the noise, but did this fix make its way into 1.61? I'm still getting similar issues there.

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. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants