[llvm] d8e1c20 - [LangRef] Clarify norecurse attribute definition when a function could occur in a cycle in dynamic call-graph (#157087)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 17 04:00:20 PDT 2025


Author: Usha Gupta
Date: 2025-09-17T12:00:16+01:00
New Revision: d8e1c20a061f4bc2cc87f3f286312f016e571469

URL: https://github.com/llvm/llvm-project/commit/d8e1c20a061f4bc2cc87f3f286312f016e571469
DIFF: https://github.com/llvm/llvm-project/commit/d8e1c20a061f4bc2cc87f3f286312f016e571469.diff

LOG: [LangRef] Clarify norecurse attribute definition when a function could occur in a cycle in dynamic call-graph (#157087)

Update the definition of the `norecurse` attribute to forbid marking a
function as `norecurse` if any call path from its body may reach it
(possibly through an external function without a visible definition).
This makes it clear that `norecurse` excludes both direct and mutual
recursion, even when recursion could arise through callees in separate
modules.

This kind of scenario only arises when norecurse is forced through a llvm user option `-mllvm -force-attribute=<fname>:norecurse`

There are a few examples in
https://github.com/llvm/llvm-project/issues/157081 which shows that the
function attribute inference incorrectly infers norecurse when the
behavior (as per new definition) is not enforced.

Added: 
    

Modified: 
    llvm/docs/LangRef.rst

Removed: 
    


################################################################################
diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 61c8415873092..5fd0f6573bb97 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2256,9 +2256,16 @@ For example:
     behavior at runtime if the function ever does dynamically return. Annotated
     functions may still raise an exception, i.a., ``nounwind`` is not implied.
 ``norecurse``
-    This function attribute indicates that the function does not call itself
-    either directly or indirectly down any possible call path. This produces
-    undefined behavior at runtime if the function ever does recurse.
+    This function attribute indicates that the function is not recursive and
+    does not participate in recursion. This means that the function never
+    occurs inside a cycle in the dynamic call graph.
+    For example:
+
+.. code-block:: llvm
+
+    fn -> other_fn -> fn       ; fn is not norecurse
+    other_fn -> fn -> other_fn ; fn is not norecurse
+    fn -> other_fn -> other_fn ; fn is norecurse
 
 .. _langref_willreturn:
 


        


More information about the llvm-commits mailing list