<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/129090>129090</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Incorrectly inferred captures(none) when a pointer is captured by a call to readonly nonunwind function without return value
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tmiasko
      </td>
    </tr>
</table>

<pre>
    FunctionAttrs assumes that readonly (or readnone) and nounwind function that
don't return a value can't capture arguments. That is incorrect, since such a
function can vary its behavior by terminating or not terminating.

An example demonstrating the issue:

```console
$ cat a.ll 
define void @f(ptr %a, ptr %b) {
start:
 call void @g(ptr %a, ptr %b)
  ret void
}

define void @g(ptr %a, ptr %b) {
start:
  %0 = icmp eq ptr %a, %b
  br i1 %0, label %bb2, label %bb1

bb1:
  br label %bb1

bb2:
  ret void
}
$ opt-21 -S --passes=function-attrs a.ll
; ModuleID = 'a.ll'
source_filename = "a.ll"

; Function Attrs: nofree norecurse nosync nounwind memory(none)
define void @f(ptr readnone captures(none) %a, ptr readnone captures(none) %b) #0 {
start:
  call void @g(ptr %a, ptr %b)
  ret void
}

; Function Attrs: nofree norecurse nosync nounwind memory(none)
define void @g(ptr readnone %a, ptr readnone %b) #0 {
start:
 %0 = icmp eq ptr %a, %b
  br i1 %0, label %bb2, label %bb1

bb1: ; preds = %bb1, %start
  br label %bb1

bb2:                                              ; preds = %start
 ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(none) }
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VU2PozYY_jXm8iqRMRCGAwfSKNIeemrvlTEvwa2xqT8yzb-vbMjMNpvtaLWa0Ugx9vP4_fbDnZMXjdiS6kiqU8aDn4xt_Sy5-8tkvRlu7Tlo4aXRnffWAXcuzOjAT9yDRT4YrW5A2Iux6VMbjYQ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