-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve duplicate crate dependencies (allocations, struct names) (#430)
- Loading branch information
Showing
20 changed files
with
257 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
[package] | ||
name = "dependency3" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
pub struct Foo { | ||
x: i32, | ||
} | ||
|
||
// Export a function that takes a struct type which differs between this crate | ||
// and the other vesion | ||
pub fn take_foo(foo: &Foo) -> i32 { | ||
foo.x | ||
} | ||
|
||
pub fn give_foo() -> Foo { | ||
Foo { x: 1 } | ||
} | ||
|
||
pub fn get_int() -> i32 { | ||
// Use a constant to force an MIR GlobalAllocation::Memory. | ||
// Use a non-i32 so there will be a conflict between this | ||
// version and the other version. The constant is also a | ||
// different value than the other version of this dependency. | ||
let one = &(1 as i8); | ||
return *one as i32 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
[workspace] | ||
members = ["main", "dependency1", "dependency2", "dependency3"] |
12 changes: 12 additions & 0 deletions
12
src/test/rmc-dependency-test/diamond-dependency/dependency1/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
[package] | ||
name = "dependency1" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
dependency3 = { path = "../dependency3" } |
13 changes: 13 additions & 0 deletions
13
src/test/rmc-dependency-test/diamond-dependency/dependency1/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
use dependency3; | ||
|
||
pub fn delegate_get_int() -> i32 { | ||
dependency3::get_int() | ||
} | ||
|
||
pub fn delegate_use_struct() -> i32 { | ||
let foo = dependency3::give_foo(); | ||
dependency3::take_foo(&foo) | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/rmc-dependency-test/diamond-dependency/dependency2/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
[package] | ||
name = "dependency2" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
dependency3 = { path = "../../dependency3" } |
13 changes: 13 additions & 0 deletions
13
src/test/rmc-dependency-test/diamond-dependency/dependency2/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
use dependency3; | ||
|
||
pub fn delegate_get_int() -> i32 { | ||
dependency3::get_int() | ||
} | ||
|
||
pub fn delegate_use_struct() -> i32 { | ||
let foo = dependency3::give_foo(); | ||
dependency3::take_foo(&foo) | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/rmc-dependency-test/diamond-dependency/dependency3/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
[package] | ||
name = "dependency3" | ||
version = "0.1.1" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
24 changes: 24 additions & 0 deletions
24
src/test/rmc-dependency-test/diamond-dependency/dependency3/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
pub struct Foo { | ||
x: i32, | ||
// This field only in this version. | ||
y: i32, | ||
} | ||
|
||
// Export a function that takes a struct type which differs between this crate | ||
// and the other vesion. | ||
pub fn take_foo(foo: &Foo) -> i32 { | ||
foo.x + foo.y | ||
} | ||
|
||
pub fn give_foo() -> Foo { | ||
Foo { x: 1, y: 2 } | ||
} | ||
|
||
pub fn get_int() -> i32 { | ||
// Use a constant to force an MIR GlobalAllocation::Memory | ||
let zero = &0; | ||
return *zero | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/rmc-dependency-test/diamond-dependency/main/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
[package] | ||
name = "main" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
dependency1 = { path = "../dependency1" } | ||
dependency2 = { path = "../dependency2" } |
14 changes: 14 additions & 0 deletions
14
src/test/rmc-dependency-test/diamond-dependency/main/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
use dependency1; | ||
use dependency2; | ||
|
||
#[no_mangle] | ||
fn harness() { | ||
assert!(dependency1::delegate_get_int() == 0); | ||
assert!(dependency2::delegate_get_int() == 1); | ||
|
||
assert!(dependency1::delegate_use_struct() == 3); | ||
assert!(dependency2::delegate_use_struct() == 1); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/rmc-dependency-test/diamond-dependency/run-dependency-test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
# Compile crates with RMC backend | ||
cd $(dirname $0) | ||
rm -rf build | ||
CARGO_TARGET_DIR=build RUST_BACKTRACE=1 RUSTFLAGS="-Z codegen-backend=gotoc --cfg=rmc" RUSTC=rmc-rustc cargo build | ||
|
||
# Convert from JSON to Gotoc | ||
cd build/debug/deps/ | ||
ls *.json | xargs symtab2gb | ||
|
||
# Add the entry point and remove unused functions | ||
goto-cc --function harness *.out -o a.out | ||
goto-instrument --drop-unused-functions a.out b.out | ||
|
||
# Run the solver | ||
RESULT="/tmp/dependency_test_result.txt" | ||
cbmc b.out &> $RESULT | ||
if grep -q "VERIFICATION SUCCESSFUL" $RESULT; then | ||
cat $RESULT | ||
echo "Successful dependency test" | ||
exit 0 | ||
else | ||
cat $RESULT | ||
echo "Failed dependency test" | ||
exit 1 | ||
fi |