dimforge / dimforge/nalgebra

Miri complaints with remove_fixed_columns/rows

Open
#1,472 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

Miri can flag errors in code that uses `remove_fixed_columns` (or `remove_fixed_rows`). It would be nice for it not to.
`Cargo.toml`:
```toml
[package]
name = "nalgebra-miri-error"
edition = "2024"

[dependencies]
nalgebra = "0.34.1"
```
`src/lib.rs`:
```rust
#[cfg(test)]
mod tests {
use nalgebra::SMatrix;

#[test]
fn it_works() {
let n: SMatrix = SMatrix::::zeros().remove_fixed_columns::<1>(0);
}
}
```
---
```sh
cargo +nightly miri test
```
```
test tests::it_works ... error: Undefined Behavior: attempting a read access using <123355> at alloc38643[0x4], but that tag does not exist in the borrow stack for this location
--> /home/tom.fryers/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nalgebra-0.34.1/src/base/edition.rs:1136:9
|
1136 | / ptr::copy(
1137 | | ptr_in.add(nrows * ncols - remaining_len),
1138 | | ptr_out.add(curr_i),
1139 | | remaining_len,
1140 | | );
| |_________^ this error occurs as part of an access at alloc38643[0x4..0x8]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <123355> was created by a SharedReadOnly retag at offsets [0x0..0x8]
--> src/lib.rs:7:37
|
7 | let n: SMatrix = SMatrix::::zeros().remove_fixed_rows::<1>(0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: <123355> was later invalidated at offsets [0x0..0x8] by a Unique function-entry retag inside this call
--> src/lib.rs:7:37
|
7 | let n: SMatrix = SMatrix::::zeros().remove_fixed_rows::<1>(0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this is on thread `tests::it_works`
= note: stack backtrace:
0: nalgebra::base::edition::compress_rows::
at /home/tom.fryers/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nalgebra-0.34.1/src/base/edition.rs:1136:9: 1140:10
1: nalgebra::base::edition::, nalgebra::Const<1>, nalgebra::ArrayStorage>>::remove_rows_generic::>
at /home/tom.fryers/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nalgebra-0.34.1/src/base/edition.rs:600:17: 606:18
2: nalgebra::base::edition::, nalgebra::Const<1>, nalgebra::ArrayStorage>>::remove_fixed_rows::<1>
at /home/tom.fryers/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nalgebra-0.34.1/src/base/edition.rs:566:9: 566:48
3: tests::it_works
at src/lib.rs:7:37: 7:92
4: tests::it_works::{closure#0}
at src/lib.rs:6:18: 6:18
```

Note that under Tree Borrows
```sh
MIRIFLAGS=-Zmiri-tree-borrows cargo +nightly miri test
```
it's OK.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.