Skip to content

Commit

Permalink
use the portable optimizer_hide() when running under Miri
Browse files Browse the repository at this point in the history
  • Loading branch information
oconnor663 committed Aug 21, 2024
1 parent 09a3462 commit aafd2f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 13 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)]
Expand All @@ -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 {
Expand Down

0 comments on commit aafd2f9

Please sign in to comment.