[PATCH] D90275: [clang][IR] Add support for leaf attribute

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 2 07:02:31 PST 2020


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/Basic/Attr.td:1435
+  let Spellings = [GCC<"leaf">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];
----------------
Should this attribute also be supported on things like ObjC method decls or other function-like interfaces?


================
Comment at: clang/include/clang/Basic/Attr.td:1436
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
----------------
This should be referring to `LeafDocs` rather than undocumented.


================
Comment at: clang/include/clang/Basic/AttrDocs.td:3909
+The ``leaf`` attribute is used as a compiler hint to improve dataflow analysis in library functions.
+Functions marked as ``leaf`` attribute are not allowed to enter their caller's translation unit.
+Therefore, they cannot use or modify any data that does not escape the current compilation unit.
----------------
as leaf -> with the leaf

I'm not certain how to interpret that functions are not allowed to enter their caller's translation unit. I sort of read that as leaf functions are not allowed to call (or otherwise jump) out of the translation unit in which they're defined -- is that about right?


================
Comment at: clang/include/clang/Basic/AttrDocs.td:3910
+Functions marked as ``leaf`` attribute are not allowed to enter their caller's translation unit.
+Therefore, they cannot use or modify any data that does not escape the current compilation unit.
+
----------------
What sort of diagnostic checking should the user expect? e.g., can the user expect Clang to diagnose obviously incorrect code like:
```
[[gnu::leaf]] void func(void (*fp)(void)) {
  fp(); // This seems like a bad thing
}
```


================
Comment at: clang/include/clang/Basic/AttrDocs.td:3913
+For more information see
+`gcc documentation <https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html>`
+}];
----------------
We should probably link to the latest docs (https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html) rather than 4.7.2.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90275/new/

https://reviews.llvm.org/D90275



More information about the cfe-commits mailing list