Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Compilation errors when including iostream in OpenMP NVPTX offloading code #40831

Closed Quuxplusone closed 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR41861
Status RESOLVED FIXED
Importance P enhancement
Reported by Patrick Atkinson (p.atkinson@bristol.ac.uk)
Reported on 2019-05-13 08:26:21 -0700
Last modified on 2019-06-25 09:06:21 -0700
Version unspecified
Hardware Other Linux
CC a.bataev@hotmail.com, Gheorghe-Teod.Bercea@ibm.com, hfinkel@anl.gov, jdoerfert@anl.gov, llvm-bugs@lists.llvm.org
Fixed by commit(s) rL360809
Attachments
Blocks
Blocked by
See also
The following code will fail to compile with Clang configured to use OpenMP
NVPTX offloading.

#include <cstdio>
#include <iostream>

int main()
{
  #pragma omp target
  {
    printf("foo\n");
  }
}

Compiler output:

~ $ clang++ test.cpp -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-
target -march=sm_60
In file included from test.cpp:2:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/iostream:39:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/ostream:38:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/ios:42:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/bits/ios_base.h:39:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/ext/atomicity.h:35:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux/bits/gthr.h:148:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux/bits/gthr-default.h:35:
In file included from /usr/include/pthread.h:24:
/usr/include/time.h:189:16: error: functions that differ only in their return
type cannot be overloaded
extern clock_t clock (void) __THROW;
       ~~~~~~~ ^
/lustre/home/br-
patkinson/modules/x86_64/llvm/install/lib/clang/9.0.0/include/__clang_cuda_device_functions.h:1496:16:
note: previous definition is here
__DEVICE__ int clock() { return __nvvm_read_ptx_sreg_clock(); }
           ~~~ ^
In file included from test.cpp:2:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/iostream:39:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/ostream:38:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/ios:42:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/bits/ios_base.h:41:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/bits/locale_classes.h:40:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/string:52:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/bits/basic_string.h:2815:
In file included from /usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/ext/string_conversions.h:41:
/usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:166:3: error: declaration
conflicts with target of using declaration already in scope
  abs(long __i) { return __builtin_labs(__i); }
  ^
/lustre/home/br-
patkinson/modules/x86_64/llvm/install/lib/clang/9.0.0/include/__clang_cuda_cmath.h:40:17:
note: target of using declaration
__DEVICE__ long abs(long __n) { return ::labs(__n); }
                ^
/usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:122:11: note: using
declaration
  using ::abs;
          ^
/usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:174:3: error: declaration
conflicts with target of using declaration already in scope
  abs(long long __x) { return __builtin_llabs (__x); }
  ^
/lustre/home/br-
patkinson/modules/x86_64/llvm/install/lib/clang/9.0.0/include/__clang_cuda_cmath.h:39:22:
note: target of using declaration
__DEVICE__ long long abs(long long __n) { return ::llabs(__n); }
                     ^
/usr/lib/gcc/x86_64-redhat-
linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:122:11: note: using
declaration
  using ::abs;
          ^
3 errors generated.

It seems there's a declaration conflict between the C standard library headers
and the '__clang_cuda' headers.

When '#include <iostream>' is removed from the above example, the code compiles
and works fine.
Quuxplusone commented 5 years ago

https://reviews.llvm.org/D61765

fixes clock and abs definitions. Will land soon.

Quuxplusone commented 5 years ago

Hi Patrick.

I just committed the fix, can you try again?

Thanks a lot!

Quuxplusone commented 5 years ago
Thank you both Johannes and Doru and apologies for not seeing that commit.

I've rebuild Clang and this error has disappeared when using GCC toolchains 4.8
and 6.1.

However, if I instruct Clang to use a GCC toolchain >= 7.0, the error with
'abs' reappears. This seems to be because libstdc++ switched to using a
separate header (bits/std_abs.h) for all 'abs' overloads.

Below is the error I get when using Clang with GCC 7.4 headers:

~ $ clang++ test.cpp -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-
target -march=sm_60 --gcc-toolchain="/projects/bristol/modules/gcc/7.4.0/"
In file included from test.cpp:2:
In file included from /projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-
linux-gnu/7.4.0/../../../../include/c++/7.4.0/iostream:39:
In file included from /projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-
linux-gnu/7.4.0/../../../../include/c++/7.4.0/ostream:38:
In file included from /projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-
linux-gnu/7.4.0/../../../../include/c++/7.4.0/ios:42:
In file included from /projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-
linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/ios_base.h:41:
In file included from /projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-
linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/locale_classes.h:40:
In file included from /projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-
linux-gnu/7.4.0/../../../../include/c++/7.4.0/string:52:
In file included from /projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-
linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/basic_string.h:6361:
In file included from /projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-
linux-gnu/7.4.0/../../../../include/c++/7.4.0/ext/string_conversions.h:41:
In file included from /projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-
linux-gnu/7.4.0/../../../../include/c++/7.4.0/cstdlib:77:
/projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-linux-
gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_abs.h:70:3: error: declaration
conflicts with target of using declaration already in scope
  abs(double __x)
  ^
/lustre/home/br-
patkinson/modules/x86_64/llvm/install/lib/clang/9.0.0/include/__clang_cuda_math_forward_declares.h:35:19:
note: target of using declaration
__DEVICE__ double abs(double);
                  ^
/projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-linux-
gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_abs.h:52:11: note: using
declaration
  using ::abs;
          ^
/projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-linux-
gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_abs.h:74:3: error: declaration
conflicts with target of using declaration already in scope
  abs(float __x)
  ^
/lustre/home/br-
patkinson/modules/x86_64/llvm/install/lib/clang/9.0.0/include/__clang_cuda_math_forward_declares.h:36:18:
note: target of using declaration
__DEVICE__ float abs(float);
                 ^
/projects/bristol/modules/gcc/7.4.0/lib/gcc/x86_64-pc-linux-
gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_abs.h:52:11: note: using
declaration
  using ::abs;
          ^
2 errors generated.
Quuxplusone commented 5 years ago

I see that now you get an error with the "double" abs instead of the "long" abs.

Quuxplusone commented 5 years ago

Yes, and moving the declarations of "float" and "double" abs in clang_cuda_cmath.h and clang_cuda_math_forward_declares.h to within the "#if !(defined(_OPENMP) && defined(__cplusplus))" block seems to fix the issue for all versions of GCC.

Quuxplusone commented 5 years ago

Hi,

I've committed a fix for this.

Can you please try the latest version of the compiler and see if the error has now disappeared.

Thanks a lot,

--Doru

Quuxplusone commented 5 years ago

The latest version of the compiler is now working correctly.

Thank you very much Doru.