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

Gulfem Savrun Yeniceri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 2 17:28:09 PST 2020


gulfem marked an inline comment as done.
gulfem added inline comments.


================
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.
----------------
aaron.ballman wrote:
> gulfem wrote:
> > aaron.ballman wrote:
> > > 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?
> > I think the description is a little confusing.
> > As far as I understand, leaf functions can actually call or jump out the the translation unit that they are defined ("Leaf functions might still call functions from other compilation units").
> > The manual refers caller function's translation unit as **current translation** unit.
> > "Calls to external functions with this attribute must return to the current compilation unit only by return or by exception handling. In particular, a leaf function is not allowed to invoke callback functions passed to it from the current compilation unit, directly call functions exported by the unit, or longjmp into the unit."
> > My interpretation of this statement is that a function marked with a leaf attribute can only return to its caller translation unit by a return or an exception, but it cannot enter into callers translation unit by invoking a callback function. 
> > Does that make sense?
> > 
> > 
> Ah, thank you for the explanation! How about: `Functions marked with the ''leaf'' attribute are not allowed to jump back into the caller's translation unit, whether through invoking a callback function, a direct external function call, use of 'longjmp', or other means.`?
> 
> Is this property transitive? e.g.,
> ```
> // TU1.c
> void func(void) {
>   leaf();
> }
> 
> void bar(void) {}
> 
> // TU2.c
> __attribute__((leaf)) void leaf(void) {
>   baz(); // Is this not allowed?
> }
> 
> // TU3.c
> void baz(void) {
>   bar();
> }
> ```
> The "directly call functions exported by the unit" makes me think the above code is fine but it could also be that "direct" in this case means "through a function designator rather than a function pointer".
I like your description, and I changed the doc that incorporates your feedback.


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