This is an archive of the discontinued LLVM Phabricator instance.

[Attrs] Elaborate on the trivial_abi documentation
Needs ReviewPublic

Authored by rnk on Dec 1 2021, 12:34 PM.

Details

Summary

My team recently answered some questions about the trivial_abi
attribute. This change attempts to distill those answers into
user-focused documentation. The previous documentation is somewhat
technical, and the new documentation tries to focus on documenting when
the attribute is safe to use, and what impact the user should expect to
see from the attribute.

Diff Detail

Event Timeline

rnk requested review of this revision.Dec 1 2021, 12:34 PM
rnk created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2021, 12:34 PM

LgenerallyGTM!

  • I would say "special member functions" instead of "methods"
  • instead of "passed indirectly by address", consider saying "passed by hidden reference" — is this something people will get, or is it a me-ism? :) There are lots of Google hits for "by hidden reference," including apparently some ABI docs.
  • "mark [...] as safe to copy as part of a function call" — Here you want a phrase that indicates "copy the bits, but don't 'copy' in the C++ sense of calling the copy constructor." One technically correct option would be to say "trivially relocate" (you mean "relocate" not "copy", and it's going to be trivial because you're just copying the bits). Alternatively, maybe say something more verbose about how the object will be seen to "jump" from one address to another with no intervening ctor or dtor calls — and this "jump" will happen precisely at the point of the call. The object goes from memory (in the caller's frame), into a register, and then back into memory again (at a new address in the callee's frame). This attribute is safe to use only when such "jumps" are unobservable by (or harmless to) the program. [I know you know this; I just don't think your wording makes it crystal clear to the future reader that this is what you mean.]
  • http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1144r5.html#non-trivial-samples contains all the examples of non-trivially-relocatable types I can think of. A big one is libc++ std::list and std::map. You allude to these with the words "Objects that register themselves into a doubly linked list", but I think that requires eagle eyes on the reader's part. "Objects whose address escapes onto the heap ... std::list" probably deserves its own dedicated bullet point, called out separately from "side table of live instances [...] debug iterators."
  • Also, objects with vptrs should never be considered trivially relocatable; but that's so arcane that I'm happy not to mention it here.
rjmccall added inline comments.Dec 1 2021, 5:03 PM
clang/include/clang/Basic/AttrDocs.td
3217

I would change the first sentence here to:

Arguments of `trivial_abi` type are destroyed in the callee, not the caller.

The rest of this paragraph seems to be restating the first sentence in ways that I would expect users to find more confusing than helpful.

You might add something like: "On some platforms, arguments are normally not destroyed until the end of the full expression containing the call; `trivial_abi` arguments will therefore be destroyed earlier than usual, immediately before the called function returns."

3267

This paragraph is redundant with the new paragraph above.