Skip to content

Make analysis/test miri-compatible and add a miri test for it #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 10, 2022

Conversation

kkysen
Copy link
Contributor

@kkysen kkysen commented Sep 25, 2022

Fixes #685.

This makes analysis/test miri-compatible when running with --features miri. This is done by using a monomorphic printf shim, since miri can't handle variadic functions like printf. Since all uses of printf in analysis/test are monomorphic (they all have the same format string), we can substitute a fn printf that is non-extern "C", non-variadic (and thus miri-compatible), and that still has the same behavior for its call sites.

Then we add a test in c2rust-pdg that runs miri on analysis/test to ensure it stays UB-free.

However, we don't yet run this test by default (it's #[ignore]d for now) as there are issues with running miri in CI (it installs xargo every time and I'm getting a permission denied error (not sure from quite what exactly), and it'd be better to install xargo upfront, not on every run). Thus, I'm #[ignore]ing it for now in 4152d34. We can get it to run in CI correctly later in another PR, but I want to merge this now and avoid over-complicating it here. The test can still be manually run with cargo test -p c2rust-pdg -- --ignored analysis_test_miri. See #698 for the tracking issue to re-enable this test by default.

The new test passing is blocked on:

It would also be nice to f ix #682, but that's not completely necessary for this (though it would create a much less noisy output).

@kkysen kkysen requested a review from aneksteind September 25, 2022 11:12
@kkysen kkysen changed the title Kkysen/analysis test miri compat Make analysis/test miri-compatible and add a miri test for it Sep 25, 2022
@kkysen kkysen mentioned this pull request Sep 26, 2022
@kkysen kkysen mentioned this pull request Sep 28, 2022
kkysen added a commit that referenced this pull request Sep 28, 2022
Fixes #680.

See the commits for the individual fixes.  The fixes are:
* 2 use after frees: 429962d, 95e483d
* 2 uninitialized reads: 50b1bb4, f6e5bce
* 2 nullptr derefs: f96bcb2, 69de3c3

Now `cd analysis/test && cargo miri run` reports no UB.  However, `miri` can't run variadic functions like `printf`, so running this requires the monomorphic `printf` shim in #686.
@kkysen kkysen force-pushed the kkysen/analysis-test-miri-compat branch from c02f3e4 to 8c42e54 Compare September 30, 2022 16:26
kkysen added 6 commits October 9, 2022 17:27
…so that it works with `miri`. This works in `analysis/test` because all `printf`s are monomorphic.
… running `miri` (which installs `xargo`) in CI.

The test can still be manually run with `cargo test -p c2rust-pdg -- --ignored analysis_test_miri`.
@kkysen kkysen force-pushed the kkysen/analysis-test-miri-compat branch from 8c42e54 to 4152d34 Compare October 10, 2022 00:37
@kkysen
Copy link
Contributor Author

kkysen commented Oct 10, 2022

There are issues with running miri in CI (it installs xargo every time and I'm getting a permission denied error (not sure from quite what exactly), and it'd be better to install xargo upfront, not on every run). Thus, I'm #[ignore]ing it for now in 4152d34. We can get it to run in CI correctly later in another PR, but I want to merge this now and avoid overcomplicating it here. The test can still be manually run with cargo test -p c2rust-pdg -- --ignored analysis_test_miri.

@kkysen kkysen merged commit e657818 into master Oct 10, 2022
@kkysen kkysen deleted the kkysen/analysis-test-miri-compat branch October 10, 2022 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a miri test for analysis/test
2 participants