Skip to content
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

add support for emitting casts to and from *mut T and Cell<T> #968

Merged
merged 14 commits into from
Jul 6, 2023

Conversation

aneksteind
Copy link
Contributor

@aneksteind aneksteind commented Jun 23, 2023

Fixes #964 . The lighttpd-minimal test had failures due to unsupported casts that the rewriter wanted to emit, namely in going to and from *mut T and Cell<T>. This adds support for those casts via:

  • an as_ptr() rewrite for Cell<T>, which produces the underlying *mut T
  • a *mut T -> *const Cell<T> -> &Cell<T> rewrite, accomplished through a pointer-to-pointer cast followed by a reborrow &*c where c: *const Cell<T>

@aneksteind aneksteind requested a review from spernsteiner June 23, 2023 15:03
@kkysen
Copy link
Contributor

kkysen commented Jun 23, 2023

The *mut T -> *const T -> *const Cell<T> is safe because Cell is #[repr(transparent)], right?

@aneksteind
Copy link
Contributor Author

The *mut T -> *const T -> *const Cell is safe because Cell is #[repr(transparent)], right?

That sounds correct to me

c2rust-analyze/tests/filecheck/cast.rs Show resolved Hide resolved
c2rust-analyze/src/rewrite/expr/mir_op.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/rewrite/expr/mir_op.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/rewrite/expr/unlower.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/rewrite/expr/unlower.rs Outdated Show resolved Hide resolved
@aneksteind aneksteind force-pushed the rewriter.cast.support branch from ca6bf03 to ec2dbc6 Compare July 5, 2023 15:12
@aneksteind aneksteind requested a review from spernsteiner July 5, 2023 15:20
@aneksteind aneksteind force-pushed the rewriter.cast.support branch from 5f67f63 to 83979c0 Compare July 5, 2023 18:31
@aneksteind aneksteind requested a review from spernsteiner July 5, 2023 18:32
@aneksteind aneksteind merged commit 97015d5 into master Jul 6, 2023
@aneksteind aneksteind deleted the rewriter.cast.support branch July 6, 2023 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rewriter: support casts needed by conversion to and from non-rewritten (fixed) types and rewritten types
3 participants