transpile: Wrap transmuted string literals in const blocks when address is taken#1628
transpile: Wrap transmuted string literals in const blocks when address is taken#1628Rua wants to merge 1 commit intoimmunant:masterfrom
const blocks when address is taken#1628Conversation
|
Converting this to draft because this code has issues with alignment. |
kkysen
left a comment
There was a problem hiding this comment.
Converting this to draft because this code has issues with alignment.
What was happening? Do we have tests for wide strings?
|
Casting a pointer from |
|
Figured something out. Wrapping the transmute in a Inline |
760f10f to
51304d1
Compare
const blocks when address is taken
kkysen
left a comment
There was a problem hiding this comment.
Inline
constis available in the nightly currently used by c2rust, but still unstable. Alternatively, the same effect might be achievable, in a cleaner way, by creating another custom proc macro crate for c2rust that does this internally.
Unstable features that have since been stabilized should be fine to use. We're trying to update our nightly version, and also upgrade the transpiler to emit edition 2024 code.
…`convert_literal` (#1633) Rather than `convert_address_of_common` completely discarding the previously translated `val` for string literals, it now does part of the correct translation in `convert_literal` so that no discarding is needed. This will probably be needed to get #1628 working, since `add_feature` (for const blocks) will have an effect even if code is discarded. Also, `as_ptr` is now used, to be consistent with other kinds of array.
kkysen
left a comment
There was a problem hiding this comment.
Could you rebase now? All of the prereq PRs should be merged now. Then I can review.
|
Lol you did one second later. |
c2rust-transpile/tests/snapshots/snapshots__transpile@wide_strings.c.2021.linux.snap
Show resolved
Hide resolved
|
Going by the problematic code posted in #1571 (comment), it looks like the type propagation issue already existed before this PR. So that would make it a separate issue that needs fixing on its own? |
2968fc5 to
02e2a6c
Compare
02e2a6c to
6f310d3
Compare
This introduces another unstable feature, but it seems like the most straightforward way to solve the issue. Borrowing a
constvalue promotes it to static, so that avoids the dangling pointers to temporaries. It could be solved by using a separateconstvariable to avoid the unstable inlineconst, but that results in even messier output code I think.