-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add tests for constant-evaluated intrinsics #1042
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bd90c8a
Move test for `needs_drop`
adpaco-aws 38f857c
Minor change to description in `needs_drop` test
adpaco-aws c4e33a7
Add test for `type_name`
adpaco-aws 66bb55f
Add test for `type_id`
adpaco-aws ffdbf62
Add test for `size_of`
adpaco-aws 23ba941
Add test for `pref_align_of`
adpaco-aws 31e4c03
Add test for `min_align_of`
adpaco-aws 307dbb0
Include a comment for `codegen_intrinsic_const`
adpaco-aws ac43650
In `type_id` test, assert no duplicates
adpaco-aws ee26a0c
Merge branch 'main' into const-eval-audit
adpaco-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Check that we get the expected results for the `min_align_of` intrinsic | ||
// with common data types | ||
#![feature(core_intrinsics)] | ||
use std::intrinsics::min_align_of; | ||
|
||
struct MyStruct {} | ||
|
||
enum MyEnum {} | ||
|
||
#[kani::proof] | ||
fn main() { | ||
// Scalar types | ||
assert!(min_align_of::<i8>() == 1); | ||
assert!(min_align_of::<i16>() == 2); | ||
assert!(min_align_of::<i32>() == 4); | ||
assert!(min_align_of::<i64>() == 8); | ||
assert!(min_align_of::<i128>() == 8); | ||
assert!(min_align_of::<isize>() == 8); | ||
assert!(min_align_of::<u8>() == 1); | ||
assert!(min_align_of::<u16>() == 2); | ||
assert!(min_align_of::<u32>() == 4); | ||
assert!(min_align_of::<u64>() == 8); | ||
assert!(min_align_of::<u128>() == 8); | ||
assert!(min_align_of::<usize>() == 8); | ||
assert!(min_align_of::<f32>() == 4); | ||
assert!(min_align_of::<f64>() == 8); | ||
assert!(min_align_of::<bool>() == 1); | ||
assert!(min_align_of::<char>() == 4); | ||
// Compound types (tuple and array) | ||
assert!(min_align_of::<(i32, i32)>() == 4); | ||
assert!(min_align_of::<[i32; 5]>() == 4); | ||
// Custom data types (struct and enum) | ||
assert!(min_align_of::<MyStruct>() == 1); | ||
assert!(min_align_of::<MyEnum>() == 1); | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/kani/Intrinsics/needs_drop.rs → ...s/kani/Intrinsics/ConstEval/needs_drop.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
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,38 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Check that we get the expected results for the `pref_align_of` intrinsic | ||
// with common data types | ||
#![feature(core_intrinsics)] | ||
use std::intrinsics::pref_align_of; | ||
|
||
struct MyStruct {} | ||
|
||
enum MyEnum {} | ||
|
||
#[kani::proof] | ||
fn main() { | ||
// Scalar types | ||
assert!(unsafe { pref_align_of::<i8>() } == 1); | ||
assert!(unsafe { pref_align_of::<i16>() } == 2); | ||
assert!(unsafe { pref_align_of::<i32>() } == 4); | ||
assert!(unsafe { pref_align_of::<i64>() } == 8); | ||
assert!(unsafe { pref_align_of::<i128>() } == 8); | ||
assert!(unsafe { pref_align_of::<isize>() } == 8); | ||
assert!(unsafe { pref_align_of::<u8>() } == 1); | ||
assert!(unsafe { pref_align_of::<u16>() } == 2); | ||
assert!(unsafe { pref_align_of::<u32>() } == 4); | ||
assert!(unsafe { pref_align_of::<u64>() } == 8); | ||
assert!(unsafe { pref_align_of::<u128>() } == 8); | ||
assert!(unsafe { pref_align_of::<usize>() } == 8); | ||
assert!(unsafe { pref_align_of::<f32>() } == 4); | ||
assert!(unsafe { pref_align_of::<f64>() } == 8); | ||
assert!(unsafe { pref_align_of::<bool>() } == 1); | ||
assert!(unsafe { pref_align_of::<char>() } == 4); | ||
// Compound types (tuple and array) | ||
assert!(unsafe { pref_align_of::<(i32, i32)>() } == 8); | ||
assert!(unsafe { pref_align_of::<[i32; 5]>() } == 4); | ||
// Custom data types (struct and enum) | ||
assert!(unsafe { pref_align_of::<MyStruct>() } == 8); | ||
assert!(unsafe { pref_align_of::<MyEnum>() } == 1); | ||
} |
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,38 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Check that we get the expected results for the `size_of` intrinsic | ||
// with common data types | ||
#![feature(core_intrinsics)] | ||
use std::intrinsics::size_of; | ||
|
||
struct MyStruct {} | ||
|
||
enum MyEnum {} | ||
|
||
#[kani::proof] | ||
fn main() { | ||
// Scalar types | ||
assert!(size_of::<i8>() == 1); | ||
assert!(size_of::<i16>() == 2); | ||
assert!(size_of::<i32>() == 4); | ||
assert!(size_of::<i64>() == 8); | ||
assert!(size_of::<i128>() == 16); | ||
assert!(size_of::<isize>() == 8); | ||
assert!(size_of::<u8>() == 1); | ||
assert!(size_of::<u16>() == 2); | ||
assert!(size_of::<u32>() == 4); | ||
assert!(size_of::<u64>() == 8); | ||
assert!(size_of::<u128>() == 16); | ||
assert!(size_of::<usize>() == 8); | ||
assert!(size_of::<f32>() == 4); | ||
assert!(size_of::<f64>() == 8); | ||
assert!(size_of::<bool>() == 1); | ||
assert!(size_of::<char>() == 4); | ||
// Compound types (tuple and array) | ||
assert!(size_of::<(i32, i32)>() == 8); | ||
assert!(size_of::<[i32; 5]>() == 20); | ||
// Custom data types (struct and enum) | ||
assert!(size_of::<MyStruct>() == 0); | ||
assert!(size_of::<MyEnum>() == 0); | ||
} |
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,49 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Check that the `type_id` intrinsic is supported with common data types | ||
// and that there are no duplicate type IDs | ||
#![feature(core_intrinsics)] | ||
use std::intrinsics::type_id; | ||
|
||
struct MyStruct {} | ||
|
||
enum MyEnum {} | ||
|
||
#[kani::proof] | ||
fn main() { | ||
let type_ids = [ | ||
// Scalar types | ||
type_id::<i8>(), | ||
type_id::<i16>(), | ||
type_id::<i32>(), | ||
type_id::<i64>(), | ||
type_id::<i128>(), | ||
type_id::<isize>(), | ||
type_id::<u8>(), | ||
type_id::<u16>(), | ||
type_id::<u32>(), | ||
type_id::<u64>(), | ||
type_id::<u128>(), | ||
type_id::<usize>(), | ||
type_id::<f32>(), | ||
type_id::<f64>(), | ||
type_id::<bool>(), | ||
type_id::<char>(), | ||
// Compound types (tuple and array) | ||
type_id::<(i32, i32)>(), | ||
type_id::<[i32; 5]>(), | ||
// Custom data types (struct and enum) | ||
type_id::<MyStruct>(), | ||
type_id::<MyEnum>(), | ||
]; | ||
|
||
// Check that there are no duplicate type IDs | ||
let i: usize = kani::any(); | ||
let j: usize = kani::any(); | ||
kani::assume(i < type_ids.len()); | ||
kani::assume(j < type_ids.len()); | ||
if i != j { | ||
assert_ne!(type_ids[i], type_ids[j]); | ||
} | ||
} |
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,38 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Check that we get the expected results for the `type_name` intrinsic | ||
// with common data types | ||
#![feature(core_intrinsics)] | ||
use std::intrinsics::type_name; | ||
|
||
struct MyStruct {} | ||
|
||
enum MyEnum {} | ||
|
||
#[kani::proof] | ||
fn main() { | ||
// Scalar types | ||
assert!(type_name::<i8>() == "i8"); | ||
assert!(type_name::<i16>() == "i16"); | ||
assert!(type_name::<i32>() == "i32"); | ||
assert!(type_name::<i64>() == "i64"); | ||
assert!(type_name::<i128>() == "i128"); | ||
assert!(type_name::<isize>() == "isize"); | ||
assert!(type_name::<u8>() == "u8"); | ||
assert!(type_name::<u16>() == "u16"); | ||
assert!(type_name::<u32>() == "u32"); | ||
assert!(type_name::<u64>() == "u64"); | ||
assert!(type_name::<u128>() == "u128"); | ||
assert!(type_name::<usize>() == "usize"); | ||
assert!(type_name::<f32>() == "f32"); | ||
assert!(type_name::<f64>() == "f64"); | ||
assert!(type_name::<bool>() == "bool"); | ||
assert!(type_name::<char>() == "char"); | ||
// Compound types (tuple and array) | ||
assert!(type_name::<(i32, i32)>() == "(i32, i32)"); | ||
assert!(type_name::<[i32; 5]>() == "[i32; 5]"); | ||
// Custom data types (struct and enum) | ||
assert!(type_name::<MyStruct>() == "type_name::MyStruct"); | ||
assert!(type_name::<MyEnum>() == "type_name::MyEnum"); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!