-
Notifications
You must be signed in to change notification settings - Fork 281
transpile: fix out-of-range literals #1442
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
10 commits
Select commit
Hold shift + click to select a range
0c9db27
transpile: partially revert 7eaa39f
kkysen 8cb5313
transpile: tests: add `out_of_range_lit.c` test for an `int32_t` that…
kkysen 380d5cb
transpile: tests: add more `out_of_range_lit.c` examples
kkysen b5758e1
transpile: tests: add a `out_of_range_lit.c` example with an explicit…
kkysen 70dac75
transpile: count `Half` and `BFloat16` as floats in `fn is_floating_t…
kkysen ffa4f4c
transpile: fix `fn literal_kind_matches_ty` to check if literals are …
kkysen c61b6ef
transpile: rename `fn literal_{kind_ => }matches_ty` since we look at…
kkysen 2e94402
transpile: clarify docs on `fn CTypeKind::guaranteed_{integer,float}_…
kkysen 813e8e3
transpile: clarify that `fn CTypeKind::guaranteed_{integer,float}_in_…
kkysen bc89539
transpile: don't handle `bool` as an integer type in `fn CTypeKind::g…
kkysen 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
9 changes: 9 additions & 0 deletions
9
c2rust-transpile/tests/snapshots/os-specific/out_of_range_lit.c
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,9 @@ | ||
| #include <stdint.h> | ||
|
|
||
| void f() { | ||
| int32_t a = 0x80000000U; | ||
| int32_t b = 0x80000000; | ||
| int32_t c = 0x8000000000000000; | ||
|
|
||
| int32_t d = (unsigned int)0x80000000U; // Test with explicit cast. | ||
| } |
22 changes: 22 additions & 0 deletions
22
c2rust-transpile/tests/snapshots/snapshots__transpile-linux@out_of_range_lit.c.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,22 @@ | ||
| --- | ||
| source: c2rust-transpile/tests/snapshots.rs | ||
| expression: cat tests/snapshots/out_of_range_lit.rs | ||
| input_file: c2rust-transpile/tests/snapshots/out_of_range_lit.c | ||
| --- | ||
| #![allow( | ||
| dead_code, | ||
| non_camel_case_types, | ||
| non_snake_case, | ||
| non_upper_case_globals, | ||
| unused_assignments, | ||
| unused_mut | ||
| )] | ||
| pub type __int32_t = i32; | ||
| pub type int32_t = __int32_t; | ||
| #[no_mangle] | ||
| pub unsafe extern "C" fn f() { | ||
| let mut a: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; | ||
| let mut b: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; | ||
| let mut c: int32_t = 0x8000000000000000 as ::core::ffi::c_ulong as int32_t; | ||
| let mut d: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; | ||
| } |
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
21 changes: 21 additions & 0 deletions
21
c2rust-transpile/tests/snapshots/snapshots__transpile-macos@out_of_range_lit.c.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,21 @@ | ||
| --- | ||
| source: c2rust-transpile/tests/snapshots.rs | ||
| expression: cat tests/snapshots/out_of_range_lit.rs | ||
| input_file: c2rust-transpile/tests/snapshots/out_of_range_lit.c | ||
| --- | ||
| #![allow( | ||
| dead_code, | ||
| non_camel_case_types, | ||
| non_snake_case, | ||
| non_upper_case_globals, | ||
| unused_assignments, | ||
| unused_mut | ||
| )] | ||
| pub type int32_t = i32; | ||
| #[no_mangle] | ||
| pub unsafe extern "C" fn f() { | ||
| let mut a: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; | ||
| let mut b: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; | ||
| let mut c: int32_t = 0x8000000000000000 as ::core::ffi::c_ulong as int32_t; | ||
| let mut d: int32_t = 0x80000000 as ::core::ffi::c_uint as int32_t; | ||
| } |
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
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.