Skip to content

Commit 911cee2

Browse files
chandraghaleChandra Ghale
andauthored
Fix for OpenMP offloading compilation error with GNU++20 option when using complex header (#115306)
The change done is to fix this issue. [[Issue](#113207)] discussion available in link provided. When using the -std=c++20 flag with -fopenmp for OpenMP offloading results in the following compilation error. Reduced test Case : ``` > cat foo.cpp #include <complex> void foo(){ } > CC -fopenmp -std=gnu++20 -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx90a foo.cpp -c In file included from foo.cpp:1: In file included from /opt/cray/pe/cce/18.0.1/cce-clang/x86_64/lib/clang/18/include/openmp_wrappers/complex:51: /opt/cray/pe/cce/18.0.1/cce-clang/x86_64/lib/clang/18/include/openmp_wrappers/complex_cmath.h:68:40: error: non-constexpr declaration of 'conj' follows constexpr declaration 68 | template <class _Tp> std::complex<_Tp> conj(const std::complex<_Tp> &__c) { | ^ /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/complex:970:5: note: previous declaration is here 970 | conj(const complex<_Tp>& __z) | ^ 1 error generated. ``` Co-authored-by: Chandra Ghale <[email protected]>
1 parent 44a6b3a commit 911cee2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

clang/lib/Headers/openmp_wrappers/complex_cmath.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ template <class _Tp> __DEVICE__ _Tp norm(const std::complex<_Tp> &__c) {
6464
}
6565

6666
// conj
67-
68-
template <class _Tp> std::complex<_Tp> conj(const std::complex<_Tp> &__c) {
67+
#ifdef _GLIBCXX20_CONSTEXPR
68+
#define CXX20_CONSTEXPR_DEVICE __DEVICE__
69+
#else
70+
#define CXX20_CONSTEXPR_DEVICE
71+
#endif
72+
template <class _Tp>
73+
CXX20_CONSTEXPR_DEVICE std::complex<_Tp> conj(const std::complex<_Tp> &__c) {
6974
return std::complex<_Tp>(__c.real(), -__c.imag());
7075
}
7176

0 commit comments

Comments
 (0)