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

    <tr>
        <th>Summary</th>
        <td>
            Potential Unsound Transformation in llvm-project/llvm/test/Transforms/ObjCARC/rle-s2l.ll
        </td>
    </tr>

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

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

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

<pre>
    ## Description

I identified a potential issue in the LLVM test suite, specifically within the file `llvm-project/llvm/test/Transforms/ObjCARC/rle-s2l.ll`. The transformation may be unsound, particularly in a multi-threaded context. This issue seems to be present in both `test5` and `test6`.

## File Location

`llvm-project/llvm/test/Transforms/ObjCARC/rle-s2l.ll`

## Transformation Details

The original code sequence is:

```llvm
define void @test6(ptr %p, ptr %n) {
  call ptr @llvm.objc.initWeak(ptr %p, ptr %n)
  %y = call ptr @llvm.objc.loadWeak(ptr %p)
  call void @use_pointer(ptr %y)
  ret void
}
```
The transformed code sequence is:
```llvm
define void @test6(ptr %p, ptr %n) {
  call ptr @llvm.objc.initWeak(ptr %p, ptr %n)
  call void @use_pointer(ptr %n)
  ret void
}
```
## Potential Issue
In the transformed code, the call to` objc_loadWeak` is omitted and the pointer `%n` is directly used. This approach assumes that the state of `%n` remains unchanged between the `objc_initWeak` and `use_pointer` calls. However, in a multi-threaded environment, it's possible that `%n` might be released by another thread after `objc_initWeak` is called. This would lead to a scenario where `use_pointer` attempts to use a released object, resulting in undefined behavior.

The original code, with the `objc_loadWeak` call, provides a safety check to ensure the object is still valid when used, which is not present in the transformed code. This omission could potentially lead to unsafe behavior in a multi-threaded context.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVkFv4zYT_TX0ZbCGQsvy-uBDNobxLZAPLYq0PS4ocWxNliJVcmTX_fXFUI7teJMtivZQIAgiZ_j43v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