<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 --- - Use of undeclared identifier 'surf2Dwrite'"
   href="https://llvm.org/bugs/show_bug.cgi?id=28919">28919</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Use of undeclared identifier 'surf2Dwrite'
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </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>llvm.org_Thaek1Ie@pmoreau.org
          </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=16923" name="attach_16923" title="File containing the CUDA kernel">attachment 16923</a> <a href="attachment.cgi?id=16923&action=edit" title="File containing the CUDA kernel">[details]</a></span>
File containing the CUDA kernel

Hello,

I wanted to give clang a go on compiling my CUDA kernels. I was able to get the
example at bit.ly/llvm-cuda to compile and run properly, but when I tried the
attached code, I got the error message "error: use of undeclared identifier
'surf2Dwrite'".

Versions used:

* CUDA: 7.5
* clang: 3.8 and 63240447ac6e ("[analyzer] Try to fix coverity CID 1360469.")
* llvm: 3.8 and 04876e5fe54e ("[X86][XOP] Add support for combining target
shuffles to VPERMIL2PD/VPERMIL2PS")

The compilation command as well as the output look as follow (with both
previously mentioned versions of clang+LLVM):

```
% clang++ -std=c++11 --cuda-path=/opt/cuda --cuda-gpu-arch=sm_30 -c surface.cu
surface.cu:15:3: error: use of undeclared identifier 'surf2Dwrite'
  surf2Dwrite(make_float4(0.0f, 0.0f, 0.0f, 1.0f), result_surface, index.x *
sizeof(float4), index.y);
  ^
1 error generated
```

If I include directly `surface_indirect_functions.h` which defines
`surf2Dwrite`, then the program does compile (well, sort of depending on the
clang version, but that looks like a different bug, so different bug report).
Playing with the CUDA headers, I added some `#error "foo"` inside
`device_functions.h` which is included by `cuda_runtime.h`, and in turns
includes `surface_indirect_functions.h`: so one right after the `#define
__DEVICE_FUNCTIONS_H__`, and another one (with a different message) in an else
clause to the `#ifdef __DEVICE_FUNCTIONS_H__`.
To resume, this is how the modified `device_functions.h` looks like:

```
#ifndef __DEVICE_FUNCTIONS_H__
#define __DEVICE_FUNCTIONS_H__
#error "foo"

// [snip] untouched content

#else
#error "bar"
#endif // __DEVICE_FUNCTIONS_H__
```

And here is the corresponding compilation output with clang:

```
% clang++ -std=c++11 --cuda-path=/opt/cuda --cuda-gpu-arch=sm_30 -c surface.cu
In file included from <built-in>:1:
In file included from
/home/pmoreau/privat/userspace/llvm/bin/../lib/clang/4.0.0/include/__clang_cuda_runtime_wrapper.h:98:
In file included from /opt/cuda/include/cuda_runtime.h:115:
/opt/cuda/include/device_functions.h:4247:2: error: "bar"
#error "bar"
 ^
In file included from <built-in>:1:
In file included from
/home/pmoreau/privat/userspace/llvm/bin/../lib/clang/4.0.0/include/__clang_cuda_runtime_wrapper.h:156:
In file included from /opt/cuda/include/math_functions.hpp:1065:
/opt/cuda/include/device_functions.h:4247:2: error: "bar"
#error "bar"
 ^
2 errors generated.
```

Apparently `__DEVICE_FUNCTIONS_H__` is getting defined by another file since we
do not get an `error: "foo"`.


Thank you in advance!
Pierre</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>