Skip to content
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

clarify when reading uninititalized memory is allowed #852

Merged
merged 4 commits into from
Sep 2, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/behavior-considered-undefined.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ code.
> **Note**: `rustc` achieves this with the unstable
> `rustc_layout_scalar_valid_range_*` attributes.

Note that uninitialized memory is also implicitly invalid for any type that has
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
a restricted set of valid values. In other words, the only cases in which
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
reading uninitialized memory is permitted is inside `union`s, and between the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably just minimize the second part to just "padding". We also don't define "compound type" anywhere, so it's probably best not to use it. We do define "user defined type" for struct/enum/union though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's all "types with fields" though that I mean by "compound type" -- so, including tuples and arrays.

RalfJung marked this conversation as resolved.
Show resolved Hide resolved
fields of a compound type (in the "padding").

A reference/pointer is "dangling" if it is null or not all of the bytes it
points to are part of the same allocation (so in particular they all have to be
part of *some* allocation). The span of bytes it points to is determined by the
Expand Down