This is an archive of the discontinued LLVM Phabricator instance.

[clang] Explicitly document that `__is_trivially_relocatable(T)` implies that `T` is implicit-lifetime.
Needs ReviewPublic

Authored by devin.jeanpierre on Feb 17 2022, 1:39 PM.

Details

Reviewers
rsmith
rjmccall
Summary

Previous change: D114732

The wording here might need some tweaking. What I want to guarantee is that everything valid for an implicit-lifetime type is also valid for these types. Either they're added to the set of implicit-lifetime types as an extension, or the operations are valid for additional non-implicit-lifetime types -- something like that.

Something to this effect is required for it to be defined behavior to memcpy to a new location, and then use the type at that new location. And so, this guarantee is necessary for __is_trivially_relocatable to be actually useful in practice. See e.g. D119385 for how this plays out.

AIUI, Clang is already fine with this and needs no code changes. Indeed, we see many types which are not what the standard would call implicit-lifetime, yet which use memcpy for copying: std::vector only checks for trivial move, and does not pair this with requiring trivial destroy. (See e.g. __construct_forward_with_exception_guarantees)

(Specifically: I believe that Clang is already fine with treating any non-polymorphic type as if it were implicit-lifetime, but I am not sure how to check this belief. There's not much in the way of explicit references to "implicit-lifetime" types in the codebase. Had a brief out of band conversation with rsmith, but may of course have misunderstood the conclusions here.)

Diff Detail

Event Timeline

devin.jeanpierre requested review of this revision.Feb 17 2022, 1:39 PM
devin.jeanpierre created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2022, 1:39 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

FWIW, I think this is a good idea. I even think that the parentheses and "Note:" are too self-deprecating, and this deserves to be a bigger deal. Perhaps __is_implicit_lifetime(T) should be an intrinsic in its own right! Then you could say very concretely that __is_trivially_relocatable(T) implies __is_implicit_lifetime(T).

Rebase off of D119385. Sorry, I'm bad at git.

devin.jeanpierre retitled this revision from Explicitly document that `__is_trivially_relocatable(T)` implies that `T` is implicit-lifetime. to [clang] Explicitly document that `__is_trivially_relocatable(T)` implies that `T` is implicit-lifetime..Feb 17 2022, 2:22 PM