<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Missing template instantiations from HIP device code"
   href="https://bugs.llvm.org/show_bug.cgi?id=44416">44416</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missing template instantiations from HIP device code
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jonathanchesterfield@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>A template instantiation in hip code compiled with cuda-device-only is missing
from the generated bitcode.

Component is HIP, but there is no HIP on the drop down list so marking as C++.

<a href="https://godbolt.org/z/GB9MY9">https://godbolt.org/z/GB9MY9</a>
clang atomic.hip --cuda-device-only -nogpulib --cuda-gpu-arch=gfx906 -emit-llvm

#define DEV __attribute__((device))

// Function emitted as expected
DEV int atomic_inc_int(int *x) {
  return __atomic_fetch_add(x, 1, __ATOMIC_SEQ_CST);
}

// Template definition
template <typename T> DEV T atomic_inc(T *x) {
  return __atomic_fetch_add(x, 1, __ATOMIC_SEQ_CST);
}

// Explict instantiation, not emitted
template DEV int atomic_inc<int>(int *);

// Use of implicit instantiation, not emitted
auto *leak_addr = &atomic_inc<int>;

Results in IR
target datalayout =
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-ni:7"
target triple = "amdgcn-amd-amdhsa"
define hidden i32 @_Z14atomic_inc_intPi(i32* nocapture %0) local_unnamed_addr
#0 {
  %2 = atomicrmw add i32* %0, i32 1 seq_cst
  ret i32 %2
}

attributes #0 = { ... }

!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 1}
!2 = !{!"clang version 10.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
6185dc0eb3ad35e1f85f2ab1038ca978563099f4)"}

Also raised on a downstream tracker before realising it reproduces on trunk
(<a href="https://github.com/ROCm-Developer-Tools/aomp/issues/67">https://github.com/ROCm-Developer-Tools/aomp/issues/67</a>)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>