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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 07:52:38 PDT 2025


================
@@ -0,0 +1,43 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --version 5
+; RUN: opt < %s -passes=function-attrs -force-lto-funcattrs -S | FileCheck %s
+
+; This test includes a call to a library function which is not marked as
+; NoCallback. Function bob() does not have internal linkage and hence prevents
+; norecurse to be added.
+
+ at .str = private unnamed_addr constant [12 x i8] c"Hello World\00", align 1
+
+; Function Attrs: nofree noinline nounwind uwtable
+define dso_local void @bob() #0 {
+; CHECK: Function Attrs: nofree noinline nounwind uwtable
+; CHECK-LABEL: define dso_local void @bob(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
+; CHECK-NEXT:    ret void
+;
+entry:
+  %call = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
+  ret void
+}
+
+; Function Attrs: nofree nounwind
+declare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #1
+
+; Function Attrs: nofree norecurse nounwind uwtable
+define dso_local noundef i32 @main() #2 {
----------------
nikic wrote:

```suggestion
define dso_local noundef i32 @main() norecurse {
```

As the attributes here are important, please try to keep them inline and minimal.

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


More information about the llvm-commits mailing list