-
Notifications
You must be signed in to change notification settings - Fork 4
Translate unions in unsafe #32
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
13140c9
Handle anonymous structs inside records
lucic71 796a454
Fix build
lucic71 f862791
Add anonymous struct tests
lucic71 d6f7748
Update tests
lucic71 d84745a
Update expected output
lucic71 59548ad
Translate unsafe unions
lucic71 f459d05
Change test expectations
lucic71 c0e2a74
Update union generated files
lucic71 f60879d
Add repr(C) to all transalted unsafe structs
lucic71 97a00fa
Handle anonymous structs inside records
lucic71 4f55f7d
Update tests
lucic71 6e1b596
Delete duplicate function definition
lucic71 6db97be
Update test expectations
lucic71 d1db80b
Delete no-compile files
lucic71 492e703
Don't overwrite memset definition on macOS
lucic71 243b4a5
Fix call of GetUserDefinedDefaultConstructor
lucic71 906ea4e
clang-format
lucic71 fe80784
Update tests
lucic71 b074d3e
Generate unsafe Default impl for union only in unsafe model
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
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 |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| 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}; | ||
| #[repr(C)] | ||
| #[derive()] | ||
| pub struct record { | ||
| pub code: Value<u16>, | ||
| pub lo: Value<u16>, | ||
| pub hi: Value<u32>, | ||
| pub pad: Value<Box<[u8]>>, | ||
| } | ||
| impl ByteRepr for record {} | ||
| #[repr(C)] | ||
| #[derive(Copy, Clone)] | ||
| pub union Container_anon_15_3 { | ||
| pub h: Value<record>, | ||
| pub raw_: Value<Box<[u8]>>, | ||
| } | ||
| impl Default for Container_anon_15_3 { | ||
| fn default() -> Self { | ||
| unsafe { std::mem::zeroed() } | ||
| } | ||
| } | ||
| #[repr(C)] | ||
| #[derive(Default)] | ||
| pub struct Container { | ||
| pub view: Value<Container_anon_15_3>, | ||
| } | ||
| impl ByteRepr for Container {} | ||
| pub fn fill_0(out: AnyPtr, cap: u64) { | ||
| let out: Value<AnyPtr> = Rc::new(RefCell::new(out)); | ||
| let cap: Value<u64> = Rc::new(RefCell::new(cap)); | ||
| let src: Value<Box<[u8]>> = Rc::new(RefCell::new(Box::new([ | ||
| 0_u8, | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| <u8>::default(), | ||
| ]))); | ||
| (*src.borrow_mut())[(0) as usize] = 2_u8; | ||
| (*src.borrow_mut())[(1) as usize] = 0_u8; | ||
| (*src.borrow_mut())[(2) as usize] = 0_u8; | ||
| (*src.borrow_mut())[(3) as usize] = 80_u8; | ||
| (*src.borrow_mut())[(4) as usize] = 127_u8; | ||
| (*src.borrow_mut())[(5) as usize] = 0_u8; | ||
| (*src.borrow_mut())[(6) as usize] = 0_u8; | ||
| (*src.borrow_mut())[(7) as usize] = 1_u8; | ||
| let n: Value<u64> = Rc::new(RefCell::new( | ||
| if ((::std::mem::size_of::<[u8; 16]>() as u64) < (*cap.borrow())) { | ||
| ::std::mem::size_of::<[u8; 16]>() as u64 | ||
| } else { | ||
| (*cap.borrow()) | ||
| }, | ||
| )); | ||
| { | ||
| (*out.borrow()).memcpy( | ||
| &((src.as_pointer() as Ptr<u8>) as Ptr<u8>).to_any(), | ||
| (*n.borrow()) as usize, | ||
| ); | ||
| (*out.borrow()).clone() | ||
| }; | ||
| } | ||
| pub fn main() { | ||
| std::process::exit(main_0()); | ||
| } | ||
| fn main_0() -> i32 { | ||
| let c: Value<Container> = <Value<Container>>::default(); | ||
| { | ||
| ((c.as_pointer()) as Ptr<Container>).to_any().memset( | ||
| (0) as u8, | ||
| ::std::mem::size_of::<Container>() as u64 as usize, | ||
| ); | ||
| ((c.as_pointer()) as Ptr<Container>).to_any().clone() | ||
| }; | ||
| ({ | ||
| let _out: AnyPtr = (((*c.borrow()).view.as_pointer()).to_strong().as_pointer() as AnyPtr); | ||
| let _cap: u64 = ::std::mem::size_of::<Container_anon_15_3>() as u64; | ||
| fill_0(_out, _cap) | ||
| }); | ||
| assert!((((*(*(*(*c.borrow()).view.borrow()).h.borrow()).code.borrow()) as i32) == (2))); | ||
| assert!( | ||
| ((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer()) | ||
| .to_strong() | ||
| .as_pointer() as Ptr::<u8>) | ||
| .offset((0) as isize) | ||
| .read()) as i32) | ||
| == (0)) | ||
| ); | ||
| assert!( | ||
| ((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer()) | ||
| .to_strong() | ||
| .as_pointer() as Ptr::<u8>) | ||
| .offset((1) as isize) | ||
| .read()) as i32) | ||
| == (80)) | ||
| ); | ||
| assert!((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(0) as usize] as i32) == (2))); | ||
| assert!( | ||
| ((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(3) as usize] as u8) as i32) == (80)) | ||
| ); | ||
| return 0; | ||
| } |
This file was deleted.
Oops, something went wrong.
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.
won't this leak memory?
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.
It's created inside the allocator of ASTContext, the node is automatically freed when ASTContext is destroyed