<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - global functions in anonymous namespace cause runtime cuda error"
   href="https://llvm.org/bugs/show_bug.cgi?id=27276">27276</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>global functions in anonymous namespace cause runtime cuda error
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>CUDA
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>crtrott@sandia.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16185" name="attach_16185" title="Reproducer">attachment 16185</a> <a href="attachment.cgi?id=16185&action=edit" title="Reproducer">[details]</a></span>
Reproducer

When defining a global function in anonymous namespace, it causes a "invalid
device function" error if the function is called from the same compilation
unit. 

i.e. in simplified form this doesn't work: 
namespace {
__global__ void foo() {}

void bar() {
   foo<<<1,1>>>();
}
}

Attached is a reproducer. The output with NVCC is:
////
[crtrott@apollo test_kernel]$ ./a.out 
Error PreKernel: no error
Error PostKernel: no error
Error PostSync: no error
Arch: 350
////

The output with clang is:
////
[crtrott@apollo test_kernel]$ ./a.out 
Error PreKernel: no error
Error PostKernel: invalid device function
Error PostSync: no error
Arch: 9
////

Compile with ./build_clang after adjusting the paths in the build script. 
For a workaround (i.e. remove the namespace) compile with 
./build_clang -DWORKAROUND</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>