3

Fix transmutes between pointers in different address spaces (e.g. fn ptrs on AVR...

 1 year ago
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.
neoserver,ios ssh client

Conversation

Contributor

@erikdesjardins 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

rustbot

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

Dec 11, 2022

// 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 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 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 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 bjorn3 Dec 14, 2022

Right

Contributor

bjorn3 commented Dec 14, 2022

@bors r+

Contributor

bors commented Dec 14, 2022

pushpin Commit 6085d33 has been approved by bjorn3

It is now in the queue for this repository.

bors

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

Dec 14, 2022

bors

merged commit ba71a63 into

rust-lang:master

Dec 14, 2022

10 checks passed

rust-timer

added a commit to rust-lang-ci/rust that referenced this pull request

Dec 14, 2022

erikdesjardins

deleted the addrspacecast branch

Dec 15, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

bjorn3

Assignees

bjorn3

Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects

None yet

Milestone

1.68.0

Development

Successfully merging this pull request may close these issues.

None yet

4 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK