Skip to content

Adjust the alignment when passing a niche as a pointer#131739

Closed
dianqk wants to merge 1 commit intorust-lang:masterfrom
dianqk:niche-ptr-align
Closed

Adjust the alignment when passing a niche as a pointer#131739
dianqk wants to merge 1 commit intorust-lang:masterfrom
dianqk:niche-ptr-align

Conversation

@dianqk
Copy link
Member

@dianqk dianqk commented Oct 15, 2024

Context: Segfault at optlevel >= 1.

When passing a niche as a pointer, we have to consider drop align and dereferenceable. The issue about dereferenceable is #131834.

Take https://rust.godbolt.org/z/rbxqKedG6 as an example: we pass E::B with a value of 32769 as a parameter, and it's clear that the alignment of this as an address is not 8.

#![feature(rustc_attrs)]

#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_layout_scalar_valid_range_end(0x7fff)]
pub struct RestrictedAddress(&'static i64);

enum E {
    A,
    B,
    C(RestrictedAddress),
}

#[no_mangle]
fn foo(a: E)  {}

Instead of dropping the align we could probably also shorten it, but we don't have a clear example to show it makes sense for optimization.

r? @the8472 or @saethlin

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants