<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 - Compiling CUDA does not predefine macros according to doc"
   href="https://bugs.llvm.org/show_bug.cgi?id=43706">43706</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Compiling CUDA does not predefine macros according to doc
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>9.0
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>eldlistmailingz@tropicsoft.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>According to the documentation regarding clang and CUDA at
<a href="https://llvm.org/docs/CompileCudaWithLLVM.html#detecting-clang-vs-nvcc-from-code">https://llvm.org/docs/CompileCudaWithLLVM.html#detecting-clang-vs-nvcc-from-code</a>,
when compiling a CUDA file with clang, the macros __clang__, __CUDA__, and
__CUDACC__ are predefined. Yet given this source as 'clang_cuda_example.cu':

#if !defined(__clang__)
#if !defined(__CUDACC__)
#if !defined(__CUDA__)
#error The predefined macros __clang__ and __CUDACC__ and __CUDA__ are not
defined
#else
#error The predefined macros __clang__ and __CUDACC__ are not defined
#endif
#elif !defined(__CUDA__)
#error The predefined macros __clang__ and __CUDA__ are not defined
#else
#error The predefined macro __clang__ is not defined
#endif
#elif !defined(__CUDACC__)
#if !defined(__CUDA__)
#error The predefined macros __CUDACC__ and __CUDA__ are not defined
#else
#error The predefined macro __CUDACC__ is not defined
#endif
#elif !defined(__CUDA__)
#error The predefined macro __CUDA__ is not defined
#endif
int main(void) { return 0; }

If I compile this with:

clang++ -c -m64 -nocudainc -nocudalib -x cuda clang_cuda_example.cu

the output is:

"clang_cuda_example.cu:17:2: error: The predefined macro __CUDACC__ is not
defined
#error The predefined macro __CUDACC__ is not defined
 ^
1 error generated when compiling for sm_20."

So either the documentation regarding clang and CUDA is incorrect or there is a
bug in clang when compiling CUDA files. If something else must be present when
compiling a CUDA file so that the __CUDAACC__ macro is predefined the
documentation should specify what that is.

I realize that my test does not actually compile any CUDA code despite the
source file ending with .cu and also telling the clang compiler, through the
'-x cuda' compiler option, that I am compiling a CUDA file. I am trying to test
clang compilation of CUDA code for a change I made in the Boost preprocessor
library, of which I am the maintainer, and I need a minimum test which shows
that clang compiling a CUDA file does indeed define the predefined macros which
the documentation says it does.</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>