-
Notifications
You must be signed in to change notification settings - Fork 5
Add ByteRepr for Ptr #225
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
Open
lucic71
wants to merge
15
commits into
Cpp2Rust:master
Choose a base branch
from
lucic71:ptr-byterepr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add ByteRepr for Ptr #225
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e75e87d
Add dummy ByteRepr for opaque structs
lucic71 7e10a1d
Add ByteRepr for Ptr and AnyPtr
lucic71 302a325
Bail-out early if reinterpreted pointer is null
lucic71 414fc4e
Allow comparison-by-address of void pointers
lucic71 500600a
Update tests
lucic71 ba3bdc7
cargo fmt
lucic71 3288f90
cargo fmt
lucic71 32d9d9c
Add arrayEndA == objectStartB test
lucic71 bd41414
Add null pointer serialization/deserialization test
lucic71 43f686d
Add ub tests for int to pointer conversion
lucic71 41fa40b
Add is_dangling
lucic71 c111151
Evict dead entries on PtrRegistry::put
lucic71 49bbc5b
Add pointer to struct serialization test
lucic71 299831f
Add c_byte_offset and c_byte_len
lucic71 2b147de
Rename swept_len to evicted_len
lucic71 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -31,3 +31,4 @@ pub unsafe fn touch_0(mut c: *mut container) { | |
| &((*c).p); | ||
| } | ||
| pub struct opaque; | ||
| impl ByteRepr for opaque {} | ||
This file contains hidden or 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,19 @@ | ||
| // panic-ub: refcount | ||
| // nondet-result: unsafe | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| int main(void) { | ||
| int arr[4] = {1, 2, 3, 4}; | ||
|
|
||
| union { | ||
| int *p; | ||
| uintptr_t bits; | ||
| } u; | ||
|
|
||
| u.p = arr; | ||
| u.bits += 100 * sizeof(int); | ||
| int *p = u.p; | ||
|
|
||
| return *p == 0 ? 0 : 1; | ||
| } |
This file contains hidden or 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,16 @@ | ||
| // panic-ub: refcount | ||
| // nondet-result: unsafe | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| int main(void) { | ||
| union { | ||
| int *p; | ||
| uintptr_t bits; | ||
| } u; | ||
|
|
||
| u.bits = 0xdeadbeef; | ||
| int *p = u.p; | ||
|
|
||
| return *p == 0 ? 0 : 1; | ||
| } |
This file contains hidden or 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,64 @@ | ||
| extern crate libcc2rs; | ||
| use libcc2rs::*; | ||
| use std::cell::RefCell; | ||
| use std::collections::BTreeMap; | ||
| use std::io::prelude::*; | ||
| use std::io::{Read, Seek, Write}; | ||
| use std::os::fd::AsFd; | ||
| use std::rc::{Rc, Weak}; | ||
| pub fn main() { | ||
| std::process::exit(main_0()); | ||
| } | ||
| fn main_0() -> i32 { | ||
| let arr: Value<Box<[i32]>> = Rc::new(RefCell::new(Box::new([1, 2, 3, 4]))); | ||
| pub struct anon_0 { | ||
| __bytes: Value<Box<[u8]>>, | ||
| } | ||
| impl anon_0 { | ||
| pub fn p(&self) -> Ptr<Ptr<i32>> { | ||
| (self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast() | ||
| } | ||
| pub fn bits(&self) -> Ptr<u64> { | ||
| (self.__bytes.as_pointer() as Ptr<u8>).reinterpret_cast() | ||
| } | ||
| } | ||
| impl Clone for anon_0 { | ||
| fn clone(&self) -> Self { | ||
| anon_0 { | ||
| __bytes: Rc::new(RefCell::new(self.__bytes.borrow().clone())), | ||
| } | ||
| } | ||
| } | ||
| impl Default for anon_0 { | ||
| fn default() -> Self { | ||
| anon_0 { | ||
| __bytes: Rc::new(RefCell::new(Box::from([0u8; 8]))), | ||
| } | ||
| } | ||
| } | ||
| impl ByteRepr for anon_0 { | ||
| fn byte_size() -> usize { | ||
| 8 | ||
| } | ||
| fn to_bytes(&self, buf: &mut [u8]) { | ||
| buf.copy_from_slice(&self.__bytes.borrow()); | ||
| } | ||
| fn from_bytes(buf: &[u8]) -> Self { | ||
| anon_0 { | ||
| __bytes: Rc::new(RefCell::new(Box::from(buf))), | ||
| } | ||
| } | ||
| }; | ||
| let u: Value<anon_0> = <Value<anon_0>>::default(); | ||
| (*u.borrow_mut()).p().write((arr.as_pointer() as Ptr<i32>)); | ||
| let rhs_0 = ((((*u.borrow()).bits().read()) as u64) | ||
| .wrapping_add(((100_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)) as u64))) | ||
| as u64; | ||
| (*u.borrow_mut()).bits().write(rhs_0); | ||
| let p: Value<Ptr<i32>> = Rc::new(RefCell::new(((*u.borrow()).p().read()).clone())); | ||
| return if (((((*p.borrow()).read()) == 0) as i32) != 0) { | ||
| 0 | ||
| } else { | ||
| 1 | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
this cursor seems like an unnecessary hack