Skip to content

Commit aa53e41

Browse files
danielsntedinski
authored andcommitted
initial rmc commit
1 parent f59811b commit aa53e41

File tree

348 files changed

+24332
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

348 files changed

+24332
-0
lines changed

CODE_OF_CONDUCT.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Code of Conduct
2+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
4+
[email protected] with any additional questions or comments.

CONTRIBUTING.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Contributing Guidelines
2+
3+
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
4+
documentation, we greatly value feedback and contributions from our community.
5+
6+
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
7+
information to effectively respond to your bug report or contribution.
8+
9+
10+
## Reporting Bugs/Feature Requests
11+
12+
We welcome you to use the GitHub issue tracker to report bugs or suggest features.
13+
14+
When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
15+
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
16+
17+
* A reproducible test case or series of steps
18+
* The version of our code being used
19+
* Any modifications you've made relevant to the bug
20+
* Anything unusual about your environment or deployment
21+
22+
23+
## Contributing via Pull Requests
24+
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
25+
26+
1. You are working against the latest source on the *main* branch.
27+
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28+
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
29+
30+
To send us a pull request, please:
31+
32+
1. Fork the repository.
33+
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34+
3. Ensure local tests pass.
35+
4. Commit to your fork using clear commit messages.
36+
5. Send us a pull request, answering any default questions in the pull request interface.
37+
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
38+
39+
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
40+
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
41+
42+
43+
## Finding contributions to work on
44+
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.
45+
46+
47+
## Code of Conduct
48+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
50+
[email protected] with any additional questions or comments.
51+
52+
53+
## Security issue notifications
54+
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
55+
56+
57+
## Licensing
58+
59+
See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Rust Model Checker (RMC)
2+
The Rust Model Checker (RMC) aims to be a bit-precise model-checker for Rust.
3+
4+
## Disclaimer
5+
RMC is currently in the initial development phase.
6+
It **does not support all rust language features**.
7+
Some unsupported (or partially supported) features will cause panics when RMC runs.
8+
In other cases, RMC will "successfully" compile the rust code under test, but may inaccuratly give either false positives or false negatives.
9+
If you encounter either false positives, or false negatives, please report them as an issue on this repository.
10+
11+
12+
## Security
13+
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
14+
15+
## Architecture
16+
TODO
17+
18+
## Developer guide
19+
TODO
20+
21+
## License
22+
### Rust compiler
23+
RMC is a fork of the rust compiler, which is primarily primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.
24+
25+
See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT), and
26+
[UPSTREAM-COPYRIGHT](UPSTREAM-COPYRIGHT) for details.
27+
28+
### RMC additions
29+
RMC is Rdistributed under the terms of both the MIT license and the Apache License (Version 2.0).
30+
31+
See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT)for details.
32+
33+
## Quickstart
34+
35+
The following will build and test `rmc`:
36+
37+
```
38+
./scripts/rmc-regression.sh
39+
```
40+
41+
## Build frontend
42+
43+
```
44+
cd RustToCBMC
45+
cp config.toml.example config.toml
46+
sed -i "" \
47+
-e "s/^#debug = .*/debug = true/" \
48+
-e "s/^#debug-assertions-std = .*/debug-assertions-std = false/" \
49+
-e "s/^#incremental = .*/incremental = true/" \
50+
-e "s/^#deny-warnings = .*/deny-warnings = false/" \
51+
config.toml
52+
./x.py build -i --stage 1 library/std
53+
export RMC_RUSTC=`find \`pwd\`/build -name "rustc" -print | grep stage1`
54+
export PATH=`pwd`/scripts:$PATH
55+
```
56+
57+
Note: You almost certainly want to use the local llvm installation instead
58+
of building llvm from scratch. You do this by setting llvm-config to the
59+
path of the local llvm-config tool in the target section of config.toml
60+
for the target you are building. For example, on MacOS,
61+
```
62+
brew install llvm
63+
echo '' >> config.toml
64+
echo '[target.x86_64-apple-darwin]' >> config.toml
65+
echo 'llvm-config = "/usr/local/opt/llvm/bin/llvm-config"' >> config.toml
66+
```
67+
68+
Note: You almost certainly want full debug information for debugging
69+
under gdb or lldb. You do this by setting debuginfo-level-rustc to 2.
70+
```
71+
sed -i "" \
72+
-e "s/^#debuginfo-level-rustc = .*/debuginfo-level-rustc = 2/" \
73+
config.toml
74+
```
75+
76+
## Install CBMC
77+
78+
CBMC has prebuilt releases [available for major platforms](https://github.com/diffblue/cbmc/releases).
79+
RMC currently works with CBMC versions 5.26 or greater.
80+
81+
### Building CBMC from source
82+
83+
If you want to build CBMC from source, however, do
84+
```
85+
git clone https://github.com/diffblue/cbmc.git
86+
cd cbmc
87+
cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DWITH_JBMC=OFF
88+
cd build
89+
make -j
90+
export PATH=$(pwd)/bin:$PATH
91+
```

cargo-rmc-tests/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
empty-main/Cargo.lock
2+
empty-main/out.main
3+
empty-main/target/
4+
simple-lib/Cargo.lock
5+
simple-lib/out.test_one_plus_two
6+
simple-lib/out.test_sum
7+
simple-lib/target/

cargo-rmc-tests/empty-main/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "empty-main"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
[dependencies]
7+
8+
[workspace]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERIFICATION SUCCESSFUL
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
fn main() {}

cargo-rmc-tests/run.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python3
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0 OR MIT
4+
"""
5+
Test runner for cargo-rmc-test directories
6+
7+
Given a cargo directory we look for expected.<func> files in the top-level. We
8+
run cargo-rmc with <func> as the entry point and make sure that every line in
9+
expected.<func> appears in the actual output.
10+
"""
11+
12+
13+
import argparse
14+
import glob
15+
import os
16+
import sys
17+
import subprocess
18+
19+
20+
def compare_output(expected, actual):
21+
"""Check that every line in expected appears in actual"""
22+
with open(expected) as f, open(actual) as g:
23+
expected = f.read().splitlines()
24+
actual = g.read().splitlines()
25+
def appears_in_actual(line):
26+
return line in actual
27+
not_found = [ line for line in expected if not appears_in_actual(line) ]
28+
for line in not_found:
29+
print(f"ERROR expected line missing: {line}", file=sys.stderr)
30+
return not_found == []
31+
32+
33+
def main():
34+
"""Check a cargo directory with cargo-rmc against expected outputs"""
35+
parser = argparse.ArgumentParser(description="Drive a cargo-rmc test")
36+
parser.add_argument("cargo_dir", help="cargo directory to verify")
37+
args = parser.parse_args()
38+
os.chdir(args.cargo_dir)
39+
exit_code = 0
40+
for expected_result in glob.glob("expected.*"):
41+
func = expected_result.split(".")[1]
42+
cmd = ["cargo", "rmc", ".", "--function", func]
43+
output = f"out.{func}"
44+
print(f"Verifying {args.cargo_dir}{func}".ljust(64+10), end="")
45+
with open(output, "w") as f:
46+
subprocess.run(cmd, stdout=f, check=True)
47+
if compare_output(expected_result, output):
48+
print("PASS")
49+
else:
50+
print("FAIL")
51+
exit_code = 1
52+
return exit_code
53+
54+
55+
if __name__ == "__main__":
56+
sys.exit(main())

cargo-rmc-tests/simple-lib/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "simple-lib"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
[dependencies]
7+
8+
[workspace]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[test_one_plus_two.assertion.1] line 30 assertion failed: p.sum() == 3: SUCCESS
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[test_sum.assertion.1] line 26 assertion failed: p.sum() == a.wrapping_add(b): SUCCESS

cargo-rmc-tests/simple-lib/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
pub mod pair;
4+
pub use pair::Pair;
5+
6+
#[cfg(test)]
7+
mod tests {
8+
#[test]
9+
fn it_works() {
10+
assert_eq!(2 + 2, 4);
11+
}
12+
}
13+
14+
#[cfg(rmc)]
15+
mod rmc_tests {
16+
use super::*;
17+
18+
fn __nondet<T>() -> T {
19+
unimplemented!()
20+
}
21+
#[allow(dead_code)]
22+
#[no_mangle]
23+
fn test_sum() {
24+
let a: u64 = __nondet();
25+
let b: u64 = __nondet();
26+
let p = Pair::new(a, b);
27+
assert!(p.sum() == a.wrapping_add(b));
28+
}
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
pub struct Pair(pub u64, pub u64);
4+
5+
impl Pair {
6+
pub fn new(a: u64, b: u64) -> Self {
7+
Pair(a, b)
8+
}
9+
pub fn sum(&self) -> u64 {
10+
self.0.wrapping_add(self.1)
11+
}
12+
}
13+
14+
#[cfg(test)]
15+
mod tests {
16+
use super::*;
17+
#[test]
18+
fn one_plus_two() {
19+
let p = Pair::new(1, 2);
20+
assert_eq!(p.sum(), 3);
21+
}
22+
}
23+
24+
#[cfg(rmc)]
25+
mod rmc_tests {
26+
use super::*;
27+
#[allow(dead_code)]
28+
#[no_mangle]
29+
fn test_one_plus_two() {
30+
let p = Pair::new(1, 2);
31+
assert!(p.sum() == 3);
32+
}
33+
}

0 commit comments

Comments
 (0)