[llvm] [LangRef] Clarify to exclude any call paths through external functions (PR #157087)
Usha Gupta via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 5 04:58:29 PDT 2025
https://github.com/usha1830 created https://github.com/llvm/llvm-project/pull/157087
Update the definition of the `norecurse` attribute to forbid marking a function as `norecurse` if any call path from its body may reach 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.
As per my understanding, this 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.
>From d3396f21bf26f00934a7640e4c624f293cc59b30 Mon Sep 17 00:00:00 2001
From: Usha Gupta <usha.gupta at arm.com>
Date: Fri, 5 Sep 2025 11:50:55 +0000
Subject: [PATCH] [LangRef] Clarify to exclude any call paths through external
functions
---
llvm/docs/LangRef.rst | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index e64b9343b7622..787592a85971e 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -2256,9 +2256,12 @@ 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 does not participate in
+ recursion, either directly or through mutual recursion. At runtime it is
+ undefined behavior if any dynamic call stack contains this function more
+ than once at the same time. A function must not be marked ``norecurse`` if,
+ along any call path starting from its body, control may reach an external
+ function whose definition is not available.
.. _langref_willreturn:
More information about the llvm-commits
mailing list