[llvm] [FuncAttrs] Relax norecurse attribute inference (PR #139943)

Usha Gupta via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 6 03:47:30 PDT 2025


usha1830 wrote:

> Reasoning about uses of F is only going to work if the function has local linkage. hasAddressTaken() does not take into account potential uses in other modules.

I was initially thinking of using ModuleSummaryIndex Analysis here to make sure we do this check in post-link LTO stage. 
However, looking at the Pass pipeline for Default LTO, I see there are three invocations of the PostOrderFunctionAttrs Pass including one in the post-link stage after whole program devirtualization. I was thinking that at this stage  the whole program references would be known and treated as single module.

We still prevent the addition of norecurse in most cases as earlier, as we are not adding norecurse solely on the basis of this check.

Thinking more about this, I can think of one scenario where things might go wrong here.
For a call stack as in earlier example:
`f1 -> f2 -> f3`
If `f3 `is an external function with an unknown definition. If f3 calls a library function like malloc which has user hooks and that in turn somehow leads to one of the callers of f3, then with this logic, f1 will get norecurse which would be incorrect.

I will look further on this. Thanks again!




https://github.com/llvm/llvm-project/pull/139943


More information about the llvm-commits mailing list