[llvm-bugs] [Bug 44416] New: Missing template instantiations from HIP device code

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 31 04:59:44 PST 2019


            Bug ID: 44416
           Summary: Missing template instantiations from HIP device code
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jonathanchesterfield at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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++.

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 =
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 (https://github.com/llvm/llvm-project.git

Also raised on a downstream tracker before realising it reproduces on trunk

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191231/45fd3d63/attachment.html>

More information about the llvm-bugs mailing list