Skip to content

Commit

Permalink
Added docs for the printf shim for miri compat.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen committed Oct 10, 2022
1 parent 654b0c0 commit 33130b7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions analysis/test/src/pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ extern "C" {
fn printf(_: *const libc::c_char, _: ...) -> libc::c_int;
}

/// `miri` does not support calling variadic functions like [`printf`],
/// but we want to test for UB, leaks, etc. using `cargo miri run`.
///
/// Luckily, all [`printf`] calls in this module are monomorphic,
/// in that they all have the same format string and same call signature,
/// so we can replace it with a [`printf`] shim that preserves the behavior
/// only for the exact monomorphic usages in this module.
///
/// Note that there is no way to detect `miri` is running,
/// so we have to put this under a separate `miri` feature
/// that should be enabled when testing under `miri` with
/// `cargo miri run --features miri`.
#[cfg(feature = "miri")]
fn printf(fmt: *const libc::c_char, i: i32) -> libc::c_int {
use std::ffi::CStr;
Expand Down

0 comments on commit 33130b7

Please sign in to comment.