-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Emit nofree attribute #156281
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
base: main
Are you sure you want to change the base?
Emit nofree attribute #156281
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -122,6 +122,9 @@ mod attr_impl { | |||||||
| const InReg = 1 << 6; | ||||||||
| const NoUndef = 1 << 7; | ||||||||
| const Writable = 1 << 8; | ||||||||
| /// It is UB for the allocation that this pointer points to to be freed | ||||||||
| /// while the function is executing. Only valid if pointee_size > 0. | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some good place to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up putting a check inside fn_abi_sanity_check(). That already verifies other ABI invariants, so I think it's also a good place to verify invariants for the attributes stored in the same structure. |
||||||||
| const NoFree = 1 << 9; | ||||||||
|
RalfJung marked this conversation as resolved.
|
||||||||
| } | ||||||||
| } | ||||||||
| rustc_data_structures::external_bitflags_debug! { ArgAttribute } | ||||||||
|
|
@@ -143,9 +146,8 @@ pub enum ArgExtension { | |||||||
| pub struct ArgAttributes { | ||||||||
| pub regular: ArgAttribute, | ||||||||
| pub arg_ext: ArgExtension, | ||||||||
| /// The minimum size of the pointee, guaranteed to be valid for the duration of the whole call | ||||||||
| /// (corresponding to LLVM's dereferenceable_or_null attributes, i.e., it is okay for this to be | ||||||||
| /// set on a null pointer, but all non-null pointers must be dereferenceable). | ||||||||
| /// If the pointer is not null, the minimum dereferenceable size of the pointee, at the time of | ||||||||
| /// function entry (for arguments) or function return (for return values). | ||||||||
| pub pointee_size: Size, | ||||||||
| /// The minimum alignment of the pointee, if any. | ||||||||
| pub pointee_align: Option<Align>, | ||||||||
|
|
@@ -408,7 +410,8 @@ impl<'a, Ty> ArgAbi<'a, Ty> { | |||||||
| .set(ArgAttribute::NoAlias) | ||||||||
| .set(ArgAttribute::CapturesAddress) | ||||||||
| .set(ArgAttribute::NonNull) | ||||||||
| .set(ArgAttribute::NoUndef); | ||||||||
| .set(ArgAttribute::NoUndef) | ||||||||
| .set(ArgAttribute::NoFree); | ||||||||
| attrs.pointee_size = layout.size; | ||||||||
| attrs.pointee_align = Some(layout.align.abi); | ||||||||
|
|
||||||||
|
|
||||||||
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.
We also don't want LLVM
dereferenceableon return values (see the comment incompiler/rustc_ty_utils/src/abi.rsthat you removed). Where is that handled now?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's handled here: https://github.com/rust-lang/rust/pull/156281/changes#diff-eb5b0fc5c9734679907fdb908c3a6b424ff723c4dceb364eef2588c996366708R404 That is, we never set NoFree on return values (and thus also not dereferenceable).
Uh oh!
There was an error while loading. Please reload this page.
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.
That's a subtle non-local invariant and you removed the comment that explains it. Please add that comment back.