Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
run Miri on CI
  • Loading branch information
RalfJung authored and tgross35 committed Mar 22, 2025
commit bec25a4e3a1c3be33ddb6eb6a1cd3c1ef7f3ae8b
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ jobs:
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

miri:
name: Miri
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install Rust (rustup)
run: rustup update nightly --no-self-update && rustup default nightly
shell: bash
- run: rustup component add miri
- run: cargo miri setup
- uses: Swatinem/rust-cache@v2
- run: ./ci/miri.sh

rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
Expand Down Expand Up @@ -190,6 +205,7 @@ jobs:
- test
- rustfmt
- clippy
- miri
runs-on: ubuntu-latest
# GitHub branch protection is exceedingly silly and treats "jobs skipped because a dependency
# failed" as success. So we have to do some contortions to ensure the job fails if any of its
Expand Down
16 changes: 16 additions & 0 deletions ci/miri.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -ex

# We need Tree Borrows as some of our raw pointer patterns are not
# compatible with Stacked Borrows.
export MIRIFLAGS="-Zmiri-tree-borrows"

# One target that sets `mem-unaligned` and one that does not,
# and a big-endian target.
TARGETS=(x86_64-unknown-linux-gnu
armv7-unknown-linux-gnueabihf
s390x-unknown-linux-gnu)
for TARGET in "${TARGETS[@]}"; do
# Only run the `mem` tests to avoid this taking too long.
cargo miri test --manifest-path testcrate/Cargo.toml --features no-asm --target $TARGET -- mem
done
6 changes: 4 additions & 2 deletions testcrate/tests/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ fn memcmp_eq() {
#[test]
fn memcmp_ne() {
let arr1 @ arr2 = gen_arr::<256>();
for i in 0..256 {
// Reduce iteration count in Miri as it is too slow otherwise.
let limit = if cfg!(miri) { 64 } else { 256 };
for i in 0..limit {
let mut diff_arr = arr1;
diff_arr.0[i] = 127;
let expect = diff_arr.0[i].cmp(&arr2.0[i]);
for k in i + 1..256 {
for k in i + 1..limit {
let result = unsafe { memcmp(diff_arr.0.as_ptr(), arr2.0.as_ptr(), k) };
assert_eq!(expect, result.cmp(&0));
}
Expand Down