-
Notifications
You must be signed in to change notification settings - Fork 304
transpile: Cast overflow builtin operands to the output type #1863
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Overflow builtins mixing 128-bit and other integer types are rejected, so | ||
| // the `reject`-prefixed functions must be missing from the snapshot. | ||
| // See https://github.com/immunant/c2rust/issues/1878. | ||
|
|
||
| int reject_uint128_operands(unsigned __int128 a, unsigned __int128 b, | ||
| unsigned long long *out) | ||
| { | ||
| return __builtin_add_overflow(a, b, out); | ||
| } | ||
|
|
||
| int reject_uint128_result(int a, int b, unsigned __int128 *out) | ||
| { | ||
| return __builtin_mul_overflow(a, b, out); | ||
| } | ||
|
|
||
| int reject_int128_operand(__int128 a, long long b, long long *out) | ||
| { | ||
| return __builtin_sub_overflow(a, b, out); | ||
| } | ||
|
|
||
| int supported_uint128(unsigned __int128 a, unsigned __int128 b, | ||
| unsigned __int128 *out) | ||
| { | ||
| return __builtin_add_overflow(a, b, out); | ||
| } | ||
|
|
||
| int supported_int128(__int128 a, __int128 b, __int128 *out) | ||
| { | ||
| return __builtin_mul_overflow(a, b, out); | ||
| } |
33 changes: 33 additions & 0 deletions
33
c2rust-transpile/tests/snapshots/snapshots__transpile@overflow_128.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,33 @@ | ||
| --- | ||
| source: c2rust-transpile/tests/snapshots.rs | ||
| expression: cat tests/snapshots/overflow_128.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 | ||
| )] | ||
| #[no_mangle] | ||
| pub unsafe extern "C" fn supported_uint128( | ||
| mut a: u128, | ||
| mut b: u128, | ||
| mut out: *mut u128, | ||
| ) -> ::core::ffi::c_int { | ||
| let (c2rust_result, c2rust_overflowed) = a.overflowing_add(b); | ||
| *out = c2rust_result; | ||
| return c2rust_overflowed as ::core::ffi::c_int; | ||
| } | ||
| #[no_mangle] | ||
| pub unsafe extern "C" fn supported_int128( | ||
| mut a: i128, | ||
| mut b: i128, | ||
| mut out: *mut i128, | ||
| ) -> ::core::ffi::c_int { | ||
| let (c2rust_result, c2rust_overflowed) = a.overflowing_mul(b); | ||
| *out = c2rust_result; | ||
| return c2rust_overflowed as ::core::ffi::c_int; | ||
| } |
34 changes: 34 additions & 0 deletions
34
c2rust-transpile/tests/snapshots/snapshots__transpile@overflow_128.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,34 @@ | ||
| --- | ||
| source: c2rust-transpile/tests/snapshots.rs | ||
| expression: cat tests/snapshots/overflow_128.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 | ||
| )] | ||
| #[unsafe(no_mangle)] | ||
| pub unsafe extern "C" fn supported_uint128( | ||
| mut a: u128, | ||
| mut b: u128, | ||
| mut out: *mut u128, | ||
| ) -> ::core::ffi::c_int { | ||
| let (c2rust_result, c2rust_overflowed) = a.overflowing_add(b); | ||
| *out = c2rust_result; | ||
| return c2rust_overflowed as ::core::ffi::c_int; | ||
| } | ||
| #[unsafe(no_mangle)] | ||
| pub unsafe extern "C" fn supported_int128( | ||
| mut a: i128, | ||
| mut b: i128, | ||
| mut out: *mut i128, | ||
| ) -> ::core::ffi::c_int { | ||
| let (c2rust_result, c2rust_overflowed) = a.overflowing_mul(b); | ||
| *out = c2rust_result; | ||
| return c2rust_overflowed as ::core::ffi::c_int; | ||
| } |
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.