Fix transmutes between pointers in different address spaces (e.g. fn ptrs on AVR...
source link: https://github.com/rust-lang/rust/pull/105578
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
Contributor
erikdesjardins commented Dec 11, 2022
Currently, this causes a verifier error (https://godbolt.org/z/YYohed4bj), since it uses bitcast
, which can't convert between address spaces.
Uncovered due to #105545 (comment)
r? @bjorn3
added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
labels
// It doesn't matter precisely how this is codegenned (as a roundtrip through memory or an addrspacecast), |
||
// as long as it doesn't cause a verifier error, e.g. by using `bitcast` (which was the case before). |
Contributor
Author
erikdesjardins Dec 11, 2022
This is codegenned as
%0 = addrspacecast ptr %x to ptr addrspace(1)
I can add a check line instead if you'd prefer
assert_eq!(src.layout.size, dst.layout.size); |
||
// NOTE(eddyb) the `from_immediate` and `to_immediate_scalar` |
||
// conversions allow handling `bool`s the same as `u8`s. |
||
let src = bx.from_immediate(src.immediate()); |
||
let src_as_dst = bx.bitcast(src, bx.backend_type(dst.layout)); |
||
// LLVM also doesn't like `bitcast`s between pointers in different address spaces. |
||
let src_as_dst = if src_is_ptr { |
Contributor
bjorn3 Dec 13, 2022
What if the from type is a pointer and the to type is an integer? Does pointercast
work for that?
Contributor
Author
erikdesjardins Dec 13, 2022
It doesn't, but that's not possible here due to src_is_ptr == dst_is_ptr
above. I can change this line to src_is_ptr && dst_is_ptr
if that would be clearer
Contributor
bjorn3 Dec 14, 2022
Right
Contributor
bjorn3 commented Dec 14, 2022
@bors r+ |
Contributor
bors commented Dec 14, 2022
added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
labels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Successfully merging this pull request may close these issues.
None yet
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK