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

    <tr>
        <th>Summary</th>
        <td>
            Functions returning non-trivially-copyable C++ types miscompile for GPU (HIP etc.)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AMDGPU,
            clang:codegen
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          efriedma-quic
      </td>
    </tr>
</table>

<pre>
    See https://github.com/llvm/llvm-project/pull/185091#discussion_r2897983863 for original context (this comment is adapted from there).

The regression test clang/test/CodeGenHIP/sret-nontrivial-copyable.hip is currently getting miscompiled.  The CHECK lines don't show it (_ZN7WrapperC2Ev is the actual relevant constructor), but there's a problem.

The signature of make() looks like this:

```
declare void @_Z4makev(ptr addrspace(5) dead_on_unwind writable sret(%struct.NontrivialPtr) align 8)
```

The signature of the constructor is this:

```
define dso_local void @_ZN7WrapperC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %this) unnamed_addr #0 align 2
```

The constructor is expected to construct the result of make() in-place. This is a problem because copying NontrivialPtr requires calling the copy constructor. C++ rules do not allow calling a copy constructor here (and some types might not have a copy constructor at all).

Ultimately, I think we need to change the signature of make(): the pointer needs to be an addrspace(0) pointer. See `ItaniumCXXABI::classifyReturnType`. See also https://github.com/llvm/llvm-project/commit/39ec9de7c23063b87f5c56f4e80c8d0f8b511a4b.

CC @VigneshwarJ @AlexVlx @arsenm
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVc1u2zgXfRp6cxGBoiRLWmjhuHWb78MUwUzbKboxKPJK4oQiVf448dsPqDhp2kkXBQyYFHV_zrlHh9x7NRrEjlTXpHqz4TFM1nU4OIVy5lffohKb3spz9xciTCEsnhQ7wg6EHUYVpthnws6EHbQ-Pf1dLc7-gyIQdlii1oQd8qaibU5YIZUX0XtlzdGxpq3bp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