back to home

rust-lang / miri

An interpreter for Rust's mid-level intermediate representation

5,967 stars
456 forks
173 issues
RustC++Shell

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing rust-lang/miri in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/rust-lang/miri)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

Miri Miri is an [Undefined Behavior][reference-ub] detection tool for Rust. It can run binaries and test suites of cargo projects and detect unsafe code that fails to uphold its safety requirements. For instance: • Out-of-bounds memory accesses and use-after-free • Invalid use of uninitialized data • Violation of intrinsic preconditions (an [ ] being reached, calling [ ] with overlapping ranges, ...) • Not sufficiently aligned memory accesses and references • Violation of basic type invariants (a that is not 0 or 1, for example, or an invalid enum discriminant) • Data races and emulation of *some* weak memory effects, i.e., atomic reads can return outdated values • **Experimental**: Violations of the [Stacked Borrows] rules governing aliasing for reference types • **Experimental**: Violations of the [Tree Borrows] aliasing rules, as an optional alternative to [Stacked Borrows] On top of that, Miri will also tell you about memory leaks: when there is memory still allocated at the end of the execution, and that memory is not reachable from a global , Miri will raise an error. You can use Miri to emulate programs on other targets, e.g. to ensure that byte-level data manipulation works correctly both on little-endian and big-endian systems. See cross-interpretation below. Miri has already discovered many real-world bugs. If you found a bug with Miri, we'd appreciate if you tell us and we'll add it to the list! By default, Miri ensures a fully deterministic execution and isolates the program from the host system. Some APIs that would usually access the host, such as gathering entropy for random number generators, environment variables, and clocks, are replaced by deterministic "fake" implementations. Set to access the real system APIs instead. (In particular, the "fake" system RNG APIs make Miri **not suited for cryptographic use**! Do not generate keys using Miri.) All that said, be aware that Miri does **not catch every violation of the Rust specification** in your program, not least because there is no such specification. Miri uses its own approximation of what is and is not Undefined Behavior in Rust. To the best of our knowledge, all Undefined Behavior that has the potential to affect a program's correctness *is* being detected by Miri (modulo [bugs][I-misses-ub]), but you should consult [the Reference][reference-ub] for the official definition of Undefined Behavior. Miri will be updated with the Rust compiler to protect against UB as it is understood by the current compiler, but it makes no promises about future versions of rustc. Further caveats that Miri users should be aware of: • If the program relies on unspecified details of how data is laid out, it will still run fine in Miri -- but might break (including causing UB) on different compiler versions or different platforms. (You can use to detect some of these cases.) • Program execution is non-deterministic when it depends, for example, on where exactly in memory allocations end up, or on the exact interleaving of concurrent threads. Miri tests one of many possible executions of your program, but it will miss bugs that only occur in a different possible execution. You can alleviate this to some extent by running Miri with different values for , but that will still by far not explore all possible executions. • Miri runs the program as a platform-independent interpreter, so the program has no access to most platform-specific APIs or FFI. A few APIs have been implemented (such as printing to stdout, accessing environment variables, and basic file system access) but most have not: for example, Miri currently does not support networking. System API support varies between targets; if you run on Windows it is a good idea to use to get better support. • Weak memory emulation is not complete: there are legal behaviors that Miri will never produce. However, Miri produces many behaviors that are hard to observe on real hardware, so it can help quite a bit in finding weak memory concurrency bugs. To be really sure about complicated atomic code, use specialized tools such as loom. Moreover, Miri fundamentally cannot ensure that your code is *sound*. [Soundness] is the property of never causing undefined behavior when invoked from arbitrary safe code, even in combination with other sound code. In contrast, Miri can just tell you if *a particular way of interacting with your code* (e.g., a test suite) causes any undefined behavior *in a particular execution* (of which there may be many, e.g. when concurrency or other forms of non-determinism are involved). When Miri finds UB, your code is definitely unsound, but when Miri does not find UB, then you may just have to test more inputs or more possible non-deterministic choices. [rust]: https://www.rust-lang.org/ [mir]: https://github.com/rust-lang/rfcs/blob/master/text/1211-mir.md [ ]: https://doc.rust-lang.org/stable/std/hint/fn.unreachable_unchecked.html [ ]: https://doc.rust-lang.org/stable/std/ptr/fn.copy_nonoverlapping.html [Stacked Borrows]: https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md [Tree Borrows]: https://perso.crans.org/vanille/treebor/ [Soundness]: https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#soundness-of-code--of-a-library [reference-ub]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html [I-misses-ub]: https://github.com/rust-lang/miri/labels/I-misses-UB Using Miri Install Miri on Rust nightly via : All the following commands assume the nightly toolchain is pinned via . Alternatively, use for each of the following commands. Now you can run your project in Miri: • To run all tests in your project through Miri, use . • If you have a binary project, you can run it through Miri using . The first time you run Miri, it will perform some extra setup and install some dependencies. It will ask you for confirmation before installing anything. supports the exact same flags as .…