-
Notifications
You must be signed in to change notification settings - Fork 281
Translate C integer types to portable Rust types #1266
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
Conversation
|
Looks like I need to learn how to update snapshot tests. |
b2a0b2f to
bd83003
Compare
kkysen
left a comment
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.
Looks like I need to learn how to update snapshot tests.
cargo test (or cargo test -p c2rust-transpile for now, as it skips a bunch of slow tests) and then cargo insta review (or INSTA_UPDATE=always cargo test and then review the *.rs diffs from git).
2457c6c to
ae1aacf
Compare
1ca5371 to
79a07c9
Compare
|
I'm seeing testsuite failures (type errors caused by differing primitive types in arithmetic) that I can't reproduce locally or on donna. I assume this has to do with type translation failing on Ubuntu 22.04 for some reason. |
kkysen
left a comment
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.
I'm seeing testsuite failures (type errors caused by differing primitive types in arithmetic) that I can't reproduce locally or on donna. I assume this has to do with type translation failing on Ubuntu 22.04 for some reason.
Are they using different LLVM/clang versions?
e218703 to
3056379
Compare
0da2644 to
de5a710
Compare
|
The remaining testsuite failures appear to be panics from (expected) arithmetic overflows that get caught in debug mode. EDIT: solved by #1273, will rebase out of this series when it lands. |
it's hard to link against libc with a direct rustc invocation. since we're testing output itself, transpiling it every time isn't critical.
by moving child generation into the trait, we avoid explicit reference to the TypedAstContext this is simpler because the only impl of this trait already stores the TypedAstContext itself, and by avoiding such aliasing we enable later implementations of mutable visitors this also allows impls of the trait to choose between all-types and only-exprs node children
this is necessary to normalize AST types between Clang 15 and below, which resolve typedefs in expression types, and Clang 16 and above, which preserve typedefs in these positions because we reify some typedef types such as `size_t`, we always want the latter behavior
this clarifies which variables refer to the same quantity in different functions this commit should have no functional changes
Co-authored-by: Khyber Sen <[email protected]>
83b0a8a to
d91b8e5
Compare
|
I think I've addressed all the comments here, and tests are green. Merging. |
info adapted from immunant/c2rust#1266 (review)
This substantially improves our fidelity of type translation for common integral types. We now recognize types like
size_tanduint8_tand convert them to the appropriate platform-independent Rust types. This is nontrivial because C-the-language does not have exact-width types and instead defines them via platform-dependent mappings to types with platform-dependent sizes, such asunsigned longandunsigned char. We have to preëmpt Clang to introduce a distinction between these types and "native" C ones when we convert the AST after exporting; to make effective use of this type information in translation we need to pass the expected type of the translated expression downward through conversion of expressions and statements.