-
Notifications
You must be signed in to change notification settings - Fork 309
refactor: compare foreign function declarations by resolved type #1936
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
ahomescu
wants to merge
3
commits into
master
from
ahomescu/fix_reorganize_definitions/compare_extern_fn_sigs
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
74 changes: 74 additions & 0 deletions
74
c2rust-refactor/tests/snapshots/reorganize_foreign_fn_type_identity.rs
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,74 @@ | ||
| #![feature(rustc_private)] | ||
| #![feature(register_tool)] | ||
| #![register_tool(c2rust)] | ||
| #![allow(non_upper_case_globals)] | ||
| #![allow(non_camel_case_types)] | ||
| #![allow(dead_code)] | ||
|
|
||
| extern crate libc; | ||
|
|
||
| // Each translation unit has its own `buf`, and the two differ in field | ||
| // visibility, so they are not unified and the second is renamed. Both units | ||
| // declare `fill` taking a `*mut buf` — spelled identically, but naming a | ||
| // different type in each unit. The two declarations therefore describe | ||
| // different functions and must not be collapsed into one. | ||
|
|
||
| pub mod a { | ||
| use libc; | ||
|
|
||
| #[c2rust::header_src = "/home/user/some/workspace/io.h:1"] | ||
| pub mod io_h { | ||
| use super::libc; | ||
|
|
||
| #[repr(C)] | ||
| #[c2rust::src_loc = "2:0"] | ||
| pub struct buf { | ||
| pub len: libc::c_int, | ||
| pad: libc::c_int, | ||
| } | ||
|
|
||
| extern "C" { | ||
| #[c2rust::src_loc = "3:0"] | ||
| pub fn fill(b: *mut buf) -> libc::c_int; | ||
| } | ||
| } | ||
|
|
||
| use io_h::{buf, fill}; | ||
|
|
||
| pub unsafe fn run() -> libc::c_int { | ||
| let mut b = std::mem::zeroed::<buf>(); | ||
| fill(&mut b) | ||
| } | ||
| } | ||
|
|
||
| pub mod b { | ||
| use libc; | ||
|
|
||
| #[c2rust::header_src = "/home/user/some/workspace/io.h:1"] | ||
| pub mod io_h { | ||
| use super::libc; | ||
|
|
||
| // Same fields as the other `buf`, but all of them are public, so the | ||
| // two are not interchangeable. | ||
| #[repr(C)] | ||
| #[c2rust::src_loc = "2:0"] | ||
| pub struct buf { | ||
| pub len: libc::c_int, | ||
| pub pad: libc::c_int, | ||
| } | ||
|
|
||
| extern "C" { | ||
| #[c2rust::src_loc = "3:0"] | ||
| pub fn fill(b: *mut buf) -> libc::c_int; | ||
| } | ||
| } | ||
|
|
||
| use io_h::{buf, fill}; | ||
|
|
||
| pub unsafe fn run() -> libc::c_int { | ||
| let mut b = std::mem::zeroed::<buf>(); | ||
| fill(&mut b) | ||
| } | ||
| } | ||
|
|
||
| fn main() {} |
68 changes: 68 additions & 0 deletions
68
...ts/snapshots__refactor-reorganize_definitions-reorganize_foreign_fn_type_identity.rs.snap
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,68 @@ | ||
| --- | ||
| source: c2rust-refactor/tests/snapshots.rs | ||
| expression: c2rust-refactor reorganize_definitions --rewrite-mode alongside -- tests/snapshots/reorganize_foreign_fn_type_identity.rs --edition 2021 | ||
| --- | ||
| #![feature(rustc_private)] | ||
| #![feature(register_tool)] | ||
| #![register_tool(c2rust)] | ||
| #![allow(non_upper_case_globals)] | ||
| #![allow(non_camel_case_types)] | ||
| #![allow(dead_code)] | ||
|
|
||
| pub mod io_h { | ||
| extern "C" { | ||
| pub fn fill(b: *mut crate::io_h::buf) -> libc::c_int; | ||
|
|
||
| #[link_name = "fill"] | ||
| pub fn fill_1(b: *mut crate::io_h::buf_1) -> libc::c_int; | ||
| } | ||
| use ::libc; | ||
|
|
||
| #[repr(C)] | ||
|
|
||
| pub struct buf { | ||
| pub len: libc::c_int, | ||
| pad: libc::c_int, | ||
| } | ||
| // Same fields as the other `buf`, but all of them are public, so the | ||
| // two are not interchangeable. | ||
| #[repr(C)] | ||
|
|
||
| pub struct buf_1 { | ||
| pub len: libc::c_int, | ||
| pub pad: libc::c_int, | ||
| } | ||
| } | ||
| extern crate libc; | ||
|
|
||
| // Each translation unit has its own `buf`, and the two differ in field | ||
| // visibility, so they are not unified and the second is renamed. Both units | ||
| // declare `fill` taking a `*mut buf` — spelled identically, but naming a | ||
| // different type in each unit. The two declarations therefore describe | ||
| // different functions and must not be collapsed into one. | ||
|
|
||
| pub mod a { | ||
| use libc; | ||
|
|
||
| use crate::io_h::buf; | ||
| use crate::io_h::fill; | ||
|
|
||
| pub unsafe fn run() -> libc::c_int { | ||
| let mut b = std::mem::zeroed::<crate::io_h::buf>(); | ||
| crate::io_h::fill(&mut b) | ||
| } | ||
| } | ||
|
|
||
| pub mod b { | ||
| use libc; | ||
|
|
||
| use crate::io_h::buf_1; | ||
| use crate::io_h::fill_1; | ||
|
|
||
| pub unsafe fn run() -> libc::c_int { | ||
| let mut b = std::mem::zeroed::<crate::io_h::buf_1>(); | ||
| crate::io_h::fill_1(&mut b) | ||
| } | ||
| } | ||
|
|
||
| fn main() {} |
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
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 is a fix for a pre-existing array issue that is now exposed by the more accurate signature comparison. I'm starting to think it should be its own separate PR, but in either case it needs to lands first. Thoughts?