-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix transmutes between pointers in different address spaces (e.g. fn ptrs on AVR) #105578
Conversation
// 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). |
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.
This is codegenned as
%0 = addrspacecast ptr %x to ptr addrspace(1)
I can add a check line instead if you'd prefer
eb5e458
to
6085d33
Compare
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 { |
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.
What if the from type is a pointer and the to type is an integer? Does pointercast
work for that?
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.
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
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.
Right
@bors r+ |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#105399 (Use more LFS functions.) - rust-lang#105578 (Fix transmutes between pointers in different address spaces (e.g. fn ptrs on AVR)) - rust-lang#105598 (explain mem::forget(env_lock) in fork/exec) - rust-lang#105624 (Fix unsoundness in bootstrap cache code) - rust-lang#105630 (Add a test for rust-lang#92481) - rust-lang#105684 (Improve rustdoc markdown variable naming) - rust-lang#105697 (Remove fee1-dead from reviewers) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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