From aafd2f924ea07539e7af83ad39615a2a0a5faa83 Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Wed, 21 Aug 2024 16:36:36 -0700 Subject: [PATCH] use the portable optimizer_hide() when running under Miri --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ src/lib.rs | 21 +++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42a533b..2a8b81a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,3 +86,24 @@ jobs: cargo build --verbose --release --target $TARGET - run: cargo test --verbose --release --features count_instructions_test - run: cargo bench --verbose + + miri: + name: Run tests under Miri + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-nightly-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} + - run: rustup toolchain install nightly --profile=minimal --no-self-update + - run: rustup default nightly + - run: rustup override set nightly + - run: rustup component add miri + - run: rustc --verbose --version + - run: cargo --verbose --version + - run: cargo miri test --verbose diff --git a/src/lib.rs b/src/lib.rs index 82fe03a..8b5743b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ #![no_std] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +#[cfg(not(miri))] #[inline] #[must_use] fn optimizer_hide(mut value: u8) -> u8 { @@ -17,6 +18,7 @@ fn optimizer_hide(mut value: u8) -> u8 { target_arch = "riscv32", target_arch = "riscv64" ))] +#[cfg(not(miri))] #[inline] #[must_use] #[allow(asm_sub_register)] @@ -28,14 +30,17 @@ fn optimizer_hide(mut value: u8) -> u8 { } } -#[cfg(not(any( - target_arch = "x86", - target_arch = "x86_64", - target_arch = "arm", - target_arch = "aarch64", - target_arch = "riscv32", - target_arch = "riscv64" -)))] +#[cfg(any( + not(any( + target_arch = "x86", + target_arch = "x86_64", + target_arch = "arm", + target_arch = "aarch64", + target_arch = "riscv32", + target_arch = "riscv64" + )), + miri +))] #[inline(never)] #[must_use] fn optimizer_hide(value: u8) -> u8 {