Repository: rust
Issue: `cargo check` results in SIGSEGV: invalid memory reference
Labels: I-crash,A-LLVM,T-compiler,C-bug

`cargo check` failed with `signal: 11, SIGSEGV: invalid memory reference`. It's the second time I've noticed `cargo check` segfaulting in the last couple of weeks or so (I don't have any output from when it first happened though).

### Code

I'm afraid I don't have a minimal example that reproduces the issue. Also, the project that triggered the segfault is proprietary, so I'm unable to share much more context. Hopefully this issue serves as a data point, if nothing else. Feel free to close it if it's completely unactionable. 

### Meta
`rustc --version --verbose`:
```
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
```

### Error output

```
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x51c173)[0x7f61fdd1d173]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f61fd45f140]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x18d7f39)[0x7f61ff0d8f39]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x18a34f4)[0x7f61ff0a44f4]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x23d8abb)[0x7f61ffbd9abb]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(_RNvXs5_Cs13w4PsU5rpo_18rustc_codegen_llvmNtB5_18LlvmCodegenBackendNtNtNtCs4Jm2qdcUo2_17rustc_codegen_ssa6traits7backend14CodegenBackend13codegen_crate+0xc26)[0x7f61ffbebfd6]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x23a5c47)[0x7f61ffba6c47]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(_RNvMs0_NtCs1jr7i5iwsdB_15rustc_interface7queriesNtB5_7Queries15ongoing_codegen+0x6c6)[0x7f61ffb8f276]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x2368974)[0x7f61ffb69974]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x234b97c)[0x7f61ffb4c97c]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x2367cfe)[0x7f61ffb68cfe]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x234cedb)[0x7f61ffb4dedb]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x234ccd5)[0x7f61ffb4dcd5]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so(+0x2378499)[0x7f61ffb79499]
/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/libstd-a46a068050a12a4b.so(rust_metadata_std_c2a6a440a415d498+0xa7073)[0x7f61fd53b073]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x8ea7)[0x7f61fd453ea7]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7f61fd376def]
    Checking <elided> v0.4.0 (ssh://git@<elided>)
    Checking sentry-core v0.25.0
   Compiling tonic-build v0.6.2
error: could not compile `<elided>`

Caused by:
  process didn't exit successfully: `rustc --crate-name <elided> --edition=2018 /home/gabi/.cargo/<elided> --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=24f8a8c64a7095a5 -C extra-filename=-24f8a8c64a7095a5 --out-dir /home/gabi/<my project>/target/debug/deps -L dependency=/home/gabi/<my project>/target/debug/deps --extern clap=/home/gabi/<my project>/target/debug/deps/libclap-49dcd6682a829e92.rmeta --extern geohash=/home/gabi/<my project>/target/debug/deps/libgeohash-68d5d5977aa3f05d.rmeta --extern geoutils=/home/gabi/<my project>/target/debug/deps/libgeoutils-fad334edbe632cf4.rmeta --extern hostname=/home/gabi/<my project>/target/debug/deps/libhostname-84ab16c8468a2917.rmeta --extern lazy_static=/home/gabi/<my project>/target/debug/deps/liblazy_static-02ff0d0fbc57b9b4.rmeta --extern multi_reader=/home/gabi/<my project>/target/debug/deps/libmulti_reader-e093299679ff291c.rmeta --extern netlink_packet_sock_diag=/home/gabi/<my project>/target/debug/deps/libnetlink_packet_sock_diag-6753e6af94ebf913.rmeta --extern netlink_sys=/home/gabi/<my project>/target/debug/deps/libnetlink_sys-076ea19b80839692.rmeta --extern radix_trie=/home/gabi/<my project>/target/debug/deps/libradix_trie-02e3725a4f4b7fc5.rmeta --extern rand=/home/gabi/<my project>/target/debug/deps/librand-d1a3911037d50efe.rmeta --extern regex=/home/gabi/<my project>/target/debug/deps/libregex-11dccc46ec595cde.rmeta --extern serde=/home/gabi/<my project>/target/debug/deps/libserde-c5aa3c7d19611668.rmeta --extern serde_yaml=/home/gabi/<my project>/target/debug/deps/libserde_yaml-b58cfb6ebc8a53b5.rmeta --extern structopt=/home/gabi/<my project>/target/debug/deps/libstructopt-afe3617a2ce1e9eb.rmeta --cap-lints allow --cfg tokio_unstable` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...
error: build failed

```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
GNU gdb (Debian 10.1-1.7) 10.1.90.20210103-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc...
[New LWP 1421619]
[New LWP 1421605]
[New LWP 1421732]
[New LWP 1421733]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
bCore was generated by `/home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f61ff0d8f39 in _RINvNtCs4Jm2qdcUo2_17rustc_codegen_ssa3mir11codegen_mirNtNtCs13w4PsU5rpo_18rustc_codegen_llvm7builder7BuilderEBV_ ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
[Current thread is 1 (Thread 0x7f61f777f700 (LWP 1421619))]
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/gabi/<my project>/target/debug/deps/libserde_derive-8bbca8a087a17512.so.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) bt
#0  0x00007f61ff0d8f39 in _RINvNtCs4Jm2qdcUo2_17rustc_codegen_ssa3mir11codegen_mirNtNtCs13w4PsU5rpo_18rustc_codegen_llvm7builder7BuilderEBV_ ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#1  0x00007f61ff0a44f4 in _RNvNvNtCs13w4PsU5rpo_18rustc_codegen_llvm4base20compile_codegen_unit14module_codegen ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#2  0x00007f61ffbd9abb in _RNvNtCs13w4PsU5rpo_18rustc_codegen_llvm4base20compile_codegen_unit ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#3  0x00007f61ffbebfd6 in _RNvXs5_Cs13w4PsU5rpo_18rustc_codegen_llvmNtB5_18LlvmCodegenBackendNtNtNtCs4Jm2qdcUo2_17rustc_codegen_ssa6traits7backend14CodegenBackend13codegen_crate () from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#4  0x00007f61ffba6c47 in _RINvMNtCs6LS5SwlmTBK_13rustc_session5utilsNtNtB5_7session7Session4timeINtNtCs6CMyLLiloLp_5alloc5boxed3BoxDNtNtCs6u8looMwBB7_4core3any3AnyEL_ENCNvNtCs1jr7i5iwsdB_15rustc_interface6passes13start_codegen0EB2l_ ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#5  0x00007f61ffb8f276 in _RNvMs0_NtCs1jr7i5iwsdB_15rustc_interface7queriesNtB5_7Queries15ongoing_codegen ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#6  0x00007f61ffb69974 in _RINvMs2_NtCs1jr7i5iwsdB_15rustc_interface7queriesNtNtB8_9interface8Compiler5enterNCNCNvCs8Y6Gq0vWek7_12rustc_driver12run_compilers_0s0_0INtNtCs6u8looMwBB7_4core6result6ResultINtNtB2f_6option6OptionNtB6_6LinkerENtCseq861t80vEc_12rustc_errors13ErrorReportedEEB1n_ ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#7  0x00007f61ffb4c97c in _RINvCskeanMsDi64Z_10rustc_span15with_source_mapINtNtCs6u8looMwBB7_4core6result6ResultuNtCseq861t80vEc_12rustc_errors13ErrorReportedENCINvNtCs1jr7i5iwsdB_15rustc_interface9interface23create_compiler_and_runBJ_NCNvCs8Y6Gq0vWek7_12rustc_driver12run_compilers_0Es_0EB3o_ ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#8  0x00007f61ffb68cfe in _RINvNtCs1jr7i5iwsdB_15rustc_interface9interface23create_compiler_and_runINtNtCs6u8looMwBB7_4core6result6ResultuNtCseq861t80vEc_12rustc_errors13ErrorReportedENCNvCs8Y6Gq0vWek7_12rustc_driver12run_compilers_0EB2z_ ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#9  0x00007f61ffb4dedb in _RINvMs_CsaNrMuJJolLo_10scoped_tlsINtB5_9ScopedKeyNtCskeanMsDi64Z_10rustc_span14SessionGlobalsE3setNCNCINvNtCs1jr7i5iwsdB_15rustc_interface4util51setup_callbacks_and_run_in_thread_pool_with_globalsNCINvNtB1H_9interface12run_compilerINtNtCs6u8looMwBB7_4core6result6ResultuNtCseq861t80vEc_12rustc_errors13ErrorReportedENCNvCs8Y6Gq0vWek7_12rustc_driver12run_compilers_0E0B3H_E00B3H_EB58_ ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#10 0x00007f61ffb4dcd5 in _RINvNtNtCsgI7AwR4XaQe_3std10sys_common9backtrace28___rust_begin_short_backtraceNCINvNtCs1jr7i5iwsdB_15rustc_interface4util51setup_callbacks_and_run_in_thread_pool_with_globalsNCINvNtB1m_9interface12run_compilerINtNtCs6u8looMwBB7_4core6result6ResultuNtCseq861t80vEc_12rustc_errors13ErrorReportedENCNvCs8Y6Gq0vWek7_12rustc_driver12run_compilers_0E0B3m_E0B3m_EB4N_.llvm.12386128522135127609 ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#11 0x00007f61ffb79499 in _RNSNvYNCINvMNtCsgI7AwR4XaQe_3std6threadNtBa_7Builder15spawn_uncheckedNCINvNtCs1jr7i5iwsdB_15rustc_interface4util51setup_callbacks_and_run_in_thread_pool_with_globalsNCINvNtB1c_9interface12run_compilerINtNtCs6u8looMwBB7_4core6result6ResultuNtCseq861t80vEc_12rustc_errors13ErrorReportedENCNvCs8Y6Gq0vWek7_12rustc_driver12run_compilers_0E0B3c_E0B3c_Es_0INtNtNtB3h_3ops8function6FnOnceuE9call_once6vtableB4D_ ()
   from /home/gabi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-028c2c06c3edd7fd.so
#12 0x00007f61fd53b073 in alloc::boxed::{impl#44}::call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> ()
    at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/alloc/src/boxed.rs:1854
#13 alloc::boxed::{impl#44}::call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> ()
    at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/alloc/src/boxed.rs:1854
#14 std::sys::unix::thread::{impl#2}::new::thread_start () at library/std/src/sys/unix/thread.rs:108
#15 0x00007f61fd453ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#16 0x00007f61fd376def in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
```

</p>
</details>