Repository: rust
Issue: SIGSEGV when compiling with --release on rustc 1.75.0 (82e1608df 2023-12-21)
Labels: I-crash,T-compiler,C-bug,S-needs-repro

I got a SIGSEGV and the compiler told me to file this issue.

Running again, I no longer get the segv but it also took like 4.5 minutes to build the release binary

<details>

```
[nix-shell:~/projects/tract/examples/onnx-mobilenet-v2]$ cargo run --release
   Compiling autocfg v1.1.0
   Compiling proc-macro2 v1.0.78
   Compiling libm v0.2.8
   Compiling unicode-ident v1.0.12
   Compiling cfg-if v1.0.0
   Compiling memchr v2.7.1
   Compiling thiserror v1.0.57
   Compiling version_check v0.9.4
   Compiling ucd-trie v0.1.6
   Compiling once_cell v1.19.0
   Compiling serde v1.0.196
   Compiling either v1.10.0
   Compiling regex-syntax v0.8.2
   Compiling num-conv v0.1.0
   Compiling anyhow v1.0.80
   Compiling powerfmt v0.2.0
   Compiling libc v0.2.153
   Compiling time-core v0.1.2
   Compiling static_assertions v1.1.0
   Compiling itoa v1.0.10
   Compiling doc-comment v0.3.3
   Compiling syn v1.0.109
   Compiling anymap2 v0.13.0
   Compiling simd-adler32 v0.3.7
   Compiling crossbeam-utils v0.8.19
   Compiling percent-encoding v2.3.1
   Compiling time-macros v0.2.17
   Compiling itertools v0.10.5
   Compiling deranged v0.3.11
   Compiling tinyvec_macros v0.1.1
   Compiling unicode-segmentation v1.11.0
   Compiling zerocopy v0.7.32
   Compiling crc32fast v1.4.0
   Compiling tinyvec v1.6.0
   Compiling smallvec v1.13.1
   Compiling ahash v0.8.8
   Compiling num-traits v0.2.18
   Compiling matrixmultiply v0.3.8
   Compiling adler v1.0.2
   Compiling same-file v1.0.6
   Compiling rawpointer v0.2.1
   Compiling walkdir v2.4.0
   Compiling miniz_oxide v0.7.2
   Compiling aho-corasick v1.1.2
   Compiling paste v1.0.14
   Compiling quote v1.0.35
   Compiling minimal-lexical v0.2.1
   Compiling hashbrown v0.14.3
   Compiling syn v2.0.50
   Compiling crossbeam-epoch v0.9.18
   Compiling nom v7.1.3
   Compiling cc v1.0.83
   Compiling unicode-normalization v0.1.22
   Compiling rustfft v6.2.0
   Compiling itertools v0.12.1
   Compiling rayon-core v1.12.1
   Compiling lazy_static v1.4.0
   Compiling strength_reduce v0.2.4
   Compiling rustix v0.38.31
   Compiling maplit v1.0.2
   Compiling crossbeam-deque v0.8.5
   Compiling flate2 v1.0.28
   Compiling getrandom v0.2.12
   Compiling lock_api v0.4.11
   Compiling log v0.4.20
   Compiling downcast-rs v1.2.0
   Compiling dyn-clone v1.0.16
   Compiling bit-vec v0.6.3
   Compiling linux-raw-sys v0.4.13
   Compiling half v2.3.1
   Compiling bitflags v2.4.2
   Compiling rand_core v0.6.4
   Compiling num-integer v0.1.46
   Compiling num-complex v0.4.5
   Compiling bit-set v0.5.3
   Compiling scopeguard v1.2.0
   Compiling ppv-lite86 v0.2.17
   Compiling filetime v0.2.23
   Compiling time v0.3.34
   Compiling primal-check v0.3.3
   Compiling transpose v0.2.2
   Compiling byteorder v1.5.0
   Compiling weezl v0.1.8
   Compiling zune-inflate v0.2.54
   Compiling spin v0.9.8
   Compiling regex-automata v0.4.5
   Compiling rand_chacha v0.3.1
   Compiling rayon v1.8.1
   Compiling ndarray v0.15.6
   Compiling flume v0.11.0
   Compiling fdeflate v0.3.4
   Compiling rand v0.8.5
   Compiling lebe v0.5.2
   Compiling bitflags v1.3.2
   Compiling color_quant v1.1.0
   Compiling bytemuck v1.14.3
   Compiling bit_field v0.10.2
   Compiling bytes v1.5.0
   Compiling exr v1.72.0
   Compiling gif v0.12.0
   Compiling qoi v0.4.1
   Compiling png v0.17.13
   Compiling memmap2 v0.9.4
   Compiling circular-buffer v0.1.6
   Compiling rand_distr v0.4.3
   Compiling thiserror-impl v1.0.57
   Compiling serde_derive v1.0.196
   Compiling liquid-derive v0.26.4
   Compiling string-interner v0.15.0
   Compiling derive-new v0.5.9
   Compiling prost-derive v0.11.9
   Compiling xattr v1.3.1
   Compiling tar v0.4.40
   Compiling regex v1.10.3
   Compiling pest v2.7.7
   Compiling jpeg-decoder v0.3.1
   Compiling prost v0.11.9
error: rustc interrupted by SIGSEGV, printing backtrace

/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x7a7e26)[0x7fc0cb1a7e26]
/nix/store/cyrrf49i2hm1w7vn2j945ic3rrzgxbqs-glibc-2.38-44/lib/libc.so.6(+0x3deb0)[0x7fc0ca854eb0]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(_RNvXsc_NtNtCs6hbyyNzuDTQ_18rustc_mir_dataflow5impls11initializedNtB5_24MaybeUninitializedPlacesNtNtB9_9framework15GenKillAnalysis17terminator_effect+0x1ac)[0x7fc0cc5dea1c]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x11d9328)[0x7fc0cbbd9328]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(_RNvXNtCsjXQfBrJPvh_19rustc_mir_transform15elaborate_dropsNtB2_14ElaborateDropsNtNtCs5pMoEhMXVVc_12rustc_middle3mir7MirPass8run_pass+0x581)[0x7fc0cba524e1]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x121928a)[0x7fc0cbc1928a]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(_RNvCsjXQfBrJPvh_19rustc_mir_transform30run_analysis_to_runtime_passes+0xe6)[0x7fc0cbac2766]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(_RNvCsjXQfBrJPvh_19rustc_mir_transform38mir_drops_elaborated_and_const_checked+0x7a9)[0x7fc0cbac2409]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x1c33fec)[0x7fc0cc633fec]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x1df56ec)[0x7fc0cc7f56ec]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x1ebc9ad)[0x7fc0cc8bc9ad]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x1d6e9b6)[0x7fc0cc76e9b6]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(_RNvNtCs6r4P5rqT0ZE_15rustc_interface6passes8analysis+0x196a)[0x7fc0cb314b4a]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x1c343ba)[0x7fc0cc6343ba]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x1dbf8a8)[0x7fc0cc7bf8a8]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x1e54093)[0x7fc0cc854093]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x1c821d3)[0x7fc0cc6821d3]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x759cbc)[0x7fc0cb159cbc]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x79b5d2)[0x7fc0cb19b5d2]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x795eb6)[0x7fc0cb195eb6]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/librustc_driver-686d20105d1a2cf7.so(+0x79d391)[0x7fc0cb19d391]
/nix/store/8x1k9hmn5mgzaad34p1i37ii7n0l16yc-rustc-1.75.0/lib/libstd-bf2160fadd66da13.so(rust_metadata_std_8b5dc8532ce6d6c4+0x95755)[0x7fc0cec23755]
/nix/store/cyrrf49i2hm1w7vn2j945ic3rrzgxbqs-glibc-2.38-44/lib/libc.so.6(+0x8b383)[0x7fc0ca8a2383]
/nix/store/cyrrf49i2hm1w7vn2j945ic3rrzgxbqs-glibc-2.38-44/lib/libc.so.6(+0x10e00c)[0x7fc0ca92500c]

note: we would appreciate a report at https://github.com/rust-lang/rust
note: backtrace dumped due to SIGSEGV! resuming signal
   Compiling tiff v0.9.1
   Compiling scan_fmt v0.2.6
   Compiling pest_meta v2.7.7
   Compiling pest_generator v2.7.7
error: could not compile `exr` (lib)
```

</details>

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6
```


<details><summary>Repro instructions</summary>
<p>

1. Checkout sonos/tract at `f48c24fe8a7b6b2b6dc9adfc838222f728272856`
2. Paste the following code in as a replacement to `examples/onnx-mobilenet-v2/main.rs` and add a dep for circular-buffer = "0.1"

```rust
use circular_buffer::CircularBuffer;
use tract_onnx::prelude::*;

fn samples_from_stdin(
    stdin: &mut std::io::StdinLock,
) -> tract_ndarray::ArrayBase<tract_ndarray::OwnedRepr<f32>, tract_ndarray::Dim<[usize; 2]>> {
    tract_ndarray::Array2::from_shape_fn((1, 1280), |(_, c)| {
        use std::io::Read;
        let mut buffer = [0u8; std::mem::size_of::<u16>()];
        stdin.read_exact(&mut buffer).unwrap();

        let sample = i16::from_le_bytes(buffer);
        sample as f32
    })
}

/// Number of spectograms we track, and the minimum input to the embedding model
const NUM_SPECTOGRAMS: usize = 76;

/// Number of embeddings we track, and the minimum input to the wakeword model
const NUM_EMBEDDINGS: usize = 16;

#[derive(Default, Clone, Debug)]
struct Melspectogram([f32; 32]);

impl Melspectogram {
    pub fn iter_mut(&mut self) -> core::slice::IterMut<'_, f32> {
        self.0.iter_mut()
    }

    pub fn iter(&self) -> core::slice::Iter<'_, f32> {
        self.0.iter()
    }
}

#[derive(Clone, Debug)]
struct Embedding([f32; 96]);

// derive(Default) doesnt work on arrays > 32, grrrr
impl Default for Embedding {
    fn default() -> Self {
        Self([0f32; 96])
    }
}

impl Embedding {
    pub fn iter_mut(&mut self) -> core::slice::IterMut<'_, f32> {
        self.0.iter_mut()
    }

    pub fn iter(&self) -> core::slice::Iter<'_, f32> {
        self.0.iter()
    }
}

/// arecord -r 16000 -f S16_LE | cargo run
fn main() -> TractResult<()> {
    let spec_model = tract_onnx::onnx()
        // load the model
        .model_for_path("melspectrogram.onnx")?
        .into_optimized()?
        .into_runnable()?;

    let embedding_model = tract_onnx::onnx()
        // load the model
        .model_for_path("embedding_model.onnx")?
        .with_input_fact(0, f32::fact([1, 76, 32, 1]).into()).unwrap()
        .into_optimized()?
        .into_runnable()?;

    let final_model = tract_onnx::onnx()
        // load the model
        .model_for_path("hey_rhasspy_v0.1.onnx")?
        .into_optimized()?
        .into_runnable()?;

    let mut spectograms = CircularBuffer::<NUM_SPECTOGRAMS, Melspectogram>::new();
    let mut embeddings = CircularBuffer::<NUM_EMBEDDINGS, Embedding>::new();

    let mut stdin = std::io::stdin().lock();
    for _ in 0..(4 * 16000 / 1280) {
        let samples: Tensor = samples_from_stdin(&mut stdin).into();

        // run the spectogram on the input
        let out = spec_model.run(tvec!(samples.into()))?.remove(0);

        // so the spectogram output is [1, 1, 5, 32] but we only care about each 32-float sequence,
        // each of which represents a spectogram. Lets iterate in those chunks and add it to our buffer.
        for chunk in out.as_slice::<f32>().unwrap().chunks(32) {
            let mut out = Melspectogram::default();
            chunk.into_iter().zip(out.iter_mut()).for_each(|(input, output)| {
                // Don't h8 this is what openWakeWords does! https://github.com/dscripka/openWakeWord/blob/main/openwakeword/utils.py#L180
                // ¯\_(ツ)_/¯  ¯\_(ツ)_/¯  ¯\_(ツ)_/¯  ¯\_(ツ)_/¯
                *output = *input / 10.0 + 2.0;
            });

            spectograms.push_back(out);
        }

        // Don't compute the embeddings unless we have a full set of input (76 spectograms)
        // for the model
        if !spectograms.is_full() {
            continue;
        }

        // Build a tensor that will be the input to the embedding model, which is [?, 76, 32, 1].
        // I presume that means [batch_size=1, num_melspectograms=76, num_spect_bins=32, ?].
        let embedding_input: Tensor = tract_ndarray::Array::<f32, tract_ndarray::Dim<[usize; 1]>>::from_iter(
            spectograms.iter().map(|spect| spect.iter()).flatten().copied(),
        ).into_shape((1, 76, 32, 1))?.into();
        // println!("model: {:?}", embedding_model.model());

        // Compute the embedding for this chunk of spectograms.
        let out = embedding_model.run(tvec!(embedding_input.into()))?.remove(0);

        // so the embedding output is [1, 1, 1, 96], lets collect that into an Embedding struct
        // and push it into our embedding buffer.
        let mut embedding = Embedding::default();
        embedding.0.clone_from_slice(out.as_slice::<f32>().unwrap());
        embeddings.push_back(embedding);


        // Don't compute the features unless we have a full set of input (16 embeddings)
        if !embeddings.is_full() {
            continue;
        }

        // Build a tensor that will be the input to the feature model, which is [1, 16, 96].
        let feature_input: Tensor = tract_ndarray::Array::<f32, tract_ndarray::Dim<[usize; 1]>>::from_iter(
            embeddings.iter().map(|spect| spect.iter()).flatten().copied(),
        ).into_shape((1, 16, 96))?.into();

        let out = final_model.run(tvec!(feature_input.into()))?.remove(0);

        println!("{:?}", out);
    }

    Ok(())
}
```

3. cd to examples/onnx-mobilenet-v2 and do cargo run --release, observe it segfault once
</p>
</details>