Skip to content

Check alignment of raw pointers in debug mode #54915

Closed
@RalfJung

Description

@RalfJung

It is UB to *r a raw pointer ("dereference", but this includes &*r) when that pointer is not aligned to its type. I propose that when compiling in debug mode, we insert a check for this to emit a panic when the pointer is not sufficiently aligned. That would essentially be the "big brother" of #52972, and the cousin of #53871.

This would have caught #54908.

However, I guess before someone starts implementing this, we should get @rust-lang/compiler to say that they think this is a good idea. It's in debug mode only, and it's a rather cheap check (as alignment is always a power of two), so I expect the perf impact to be acceptable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions