https://bugs.llvm.org/show_bug.cgi?id=43706

            Bug ID: 43706
           Summary: Compiling CUDA does not predefine macros according to
                    doc
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

According to the documentation regarding clang and CUDA at
https://llvm.org/docs/CompileCudaWithLLVM.html#detecting-clang-vs-nvcc-from-code,
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to