Repository navigation
transpile: Various fixes to type handling for builtins #1860
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
Rua
wants to merge
7
commits into
immunant:master
Choose a base branch
from
Rua:builtin-expected-type
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c2b4465
transpile: Rename `bubble_expr_types` and update documentation to bet…
Rua b78d885
transpile: Add `builtin_types.c` snapshot test
Rua 7fb445e
transpile: For `__builtin_object_size`, cast if branches rather than …
Rua 44026a4
transpile: Override `__builtin_object_size` call result type to `Size`
Rua f341253
transpile: Pass result type to `convert_builtin`
Rua ad2ec20
transpile: Lift `Ok` out of `match` in `convert_builtin`
Rua cb380f9
transpile: Cast to expected type in `convert_builtin`
Rua 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,16 @@ | ||
| #include <stdint.h> | ||
|
|
||
| void test_builtin_expected_type(double d, int y) { | ||
| int32_t ffs = __builtin_ffs(y); | ||
| int32_t clz = __builtin_clz((unsigned)y); | ||
| int32_t isnan = __builtin_isnan(d); | ||
| int32_t isinf_sign = __builtin_isinf_sign(d); | ||
| int32_t constant_p = __builtin_constant_p(y); | ||
| int32_t cond = y ? __builtin_ffs(y) : 0; | ||
| } | ||
|
|
||
| void test_builtin_object_size(void) { | ||
| int x = 0; | ||
| unsigned long n = __builtin_object_size(&x, 1); | ||
| unsigned long n2 = (unsigned long)__builtin_object_size(&x, 1); | ||
| } |
53 changes: 53 additions & 0 deletions
53
c2rust-transpile/tests/snapshots/snapshots__transpile@builtin_types.c.2021.clang15.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,53 @@ | ||
| --- | ||
| source: c2rust-transpile/tests/snapshots.rs | ||
| expression: cat tests/snapshots/builtin_types.2021.clang15.rs | ||
| --- | ||
| #![allow( | ||
| clippy::missing_safety_doc, | ||
| dead_code, | ||
| non_camel_case_types, | ||
| non_snake_case, | ||
| non_upper_case_globals, | ||
| unused_assignments, | ||
| unused_mut | ||
| )] | ||
| #![feature(raw_ref_op)] | ||
| pub type int32_t = i32; | ||
| #[no_mangle] | ||
| pub unsafe extern "C" fn test_builtin_expected_type( | ||
| mut d: ::core::ffi::c_double, | ||
| mut y: ::core::ffi::c_int, | ||
| ) { | ||
| let mut ffs: int32_t = (if y == 0 { 0 } else { y.trailing_zeros() + 1 }) as int32_t; | ||
| let mut clz: int32_t = (y as ::core::ffi::c_uint).leading_zeros() as int32_t; | ||
| let mut isnan: int32_t = d.is_nan() as int32_t; | ||
| let mut isinf_sign: int32_t = if d.is_infinite() { | ||
| if d.is_sign_positive() { | ||
| 1 as int32_t | ||
| } else { | ||
| -1 as int32_t | ||
| } | ||
| } else { | ||
| 0 as int32_t | ||
| }; | ||
| let mut constant_p: int32_t = 0 as int32_t; | ||
| let mut cond: int32_t = if y != 0 { | ||
| (if y == 0 { 0 } else { y.trailing_zeros() + 1 }) as int32_t | ||
| } else { | ||
| 0 as int32_t | ||
| }; | ||
| } | ||
| #[no_mangle] | ||
| pub unsafe extern "C" fn test_builtin_object_size() { | ||
| let mut x: ::core::ffi::c_int = 0 as ::core::ffi::c_int; | ||
| let mut n: ::core::ffi::c_ulong = (if 1 as ::core::ffi::c_int & 2 == 0 { | ||
| -1isize as usize | ||
| } else { | ||
| 0usize | ||
| }) as ::core::ffi::c_ulong; | ||
| let mut n2: ::core::ffi::c_ulong = (if 1 as ::core::ffi::c_int & 2 == 0 { | ||
| -1isize as usize | ||
| } else { | ||
| 0usize | ||
| }) as ::core::ffi::c_ulong; | ||
| } |
53 changes: 53 additions & 0 deletions
53
c2rust-transpile/tests/snapshots/snapshots__transpile@builtin_types.c.2024.clang15.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,53 @@ | ||
| --- | ||
| source: c2rust-transpile/tests/snapshots.rs | ||
| expression: cat tests/snapshots/builtin_types.2024.clang15.rs | ||
| --- | ||
| #![allow( | ||
| clippy::missing_safety_doc, | ||
| dead_code, | ||
| non_camel_case_types, | ||
| non_snake_case, | ||
| non_upper_case_globals, | ||
| unsafe_op_in_unsafe_fn, | ||
| unused_assignments, | ||
| unused_mut | ||
| )] | ||
| pub type int32_t = i32; | ||
| #[unsafe(no_mangle)] | ||
| pub unsafe extern "C" fn test_builtin_expected_type( | ||
| mut d: ::core::ffi::c_double, | ||
| mut y: ::core::ffi::c_int, | ||
| ) { | ||
| let mut ffs: int32_t = (if y == 0 { 0 } else { y.trailing_zeros() + 1 }) as int32_t; | ||
| let mut clz: int32_t = (y as ::core::ffi::c_uint).leading_zeros() as int32_t; | ||
| let mut isnan: int32_t = d.is_nan() as int32_t; | ||
| let mut isinf_sign: int32_t = if d.is_infinite() { | ||
| if d.is_sign_positive() { | ||
| 1 as int32_t | ||
| } else { | ||
| -1 as int32_t | ||
| } | ||
| } else { | ||
| 0 as int32_t | ||
| }; | ||
| let mut constant_p: int32_t = 0 as int32_t; | ||
| let mut cond: int32_t = if y != 0 { | ||
| (if y == 0 { 0 } else { y.trailing_zeros() + 1 }) as int32_t | ||
| } else { | ||
| 0 as int32_t | ||
| }; | ||
| } | ||
| #[unsafe(no_mangle)] | ||
| pub unsafe extern "C" fn test_builtin_object_size() { | ||
| let mut x: ::core::ffi::c_int = 0 as ::core::ffi::c_int; | ||
| let mut n: ::core::ffi::c_ulong = (if 1 as ::core::ffi::c_int & 2 == 0 { | ||
| -1isize as usize | ||
| } else { | ||
| 0usize | ||
| }) as ::core::ffi::c_ulong; | ||
| let mut n2: ::core::ffi::c_ulong = (if 1 as ::core::ffi::c_int & 2 == 0 { | ||
| -1isize as usize | ||
| } else { | ||
| 0usize | ||
| }) as ::core::ffi::c_ulong; | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.