Skip to content
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

crucible-mir: Properly parse ArrayToPointer casts #1225

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crucible-mir/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# next -- TBA

* Fix a bug in which `crucible-mir` would fail to parse MIR JSON code involving
casts from array references to pointers.

# 0.2 -- 2024-02-05

* `crucible-mir` now supports the `nightly-2023-01-23` Rust toolchain. Some of
Expand Down
4 changes: 3 additions & 1 deletion crucible-mir/src/Mir/JSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,11 @@ instance FromJSON CastKind where
Just (String "Pointer(MutToConstPointer)") -> pure MutToConstPointer
Just (String "UnsizeVtable") -> UnsizeVtable <$> v .: "vtable"
-- TODO: actually plumb this information through if it is relevant
-- instead of using Misc
-- instead of using Misc. See
-- https://github.com/GaloisInc/crucible/issues/1223
Just (String "PointerExposeAddress") -> pure Misc
Just (String "PointerFromExposedAddress") -> pure Misc
Just (String "Pointer(ArrayToPointer)") -> pure Misc
Just (String "DynStar") -> pure Misc
Just (String "IntToInt") -> pure Misc
Just (String "FloatToInt") -> pure Misc
Expand Down
2 changes: 1 addition & 1 deletion crucible-mir/src/Mir/Mir.hs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ data Vtable = Vtable
}
deriving (Show, Eq, Ord, Generic)

-- TODO: add other castkinds (see json)
-- TODO: add other castkinds (see https://github.com/GaloisInc/crucible/issues/1223)
data CastKind =
Misc
| ReifyFnPointer
Expand Down
20 changes: 20 additions & 0 deletions crux-mir/test/conc_eval/ptr/coerce_array_to_pointer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type T = u64;
const COUNT: usize = 16;

pub fn output_array(src: &[T; COUNT], dst: *mut T) {
unsafe {
std::ptr::copy(src as *const T, dst, COUNT);
}
}

#[cfg_attr(crux, crux::test)]
pub fn crux_test() -> T {
let src: &[T; COUNT] = &[42; COUNT];
let dst: &mut [T; COUNT] = &mut [0; COUNT];
output_array(src, dst as *mut T);
dst[0]
}

pub fn main() {
println!("{:?}", crux_test());
}
Loading