[PATCH] D97404: [CUDA, test-suite] Disable testing of non-FP complex types.

Artem Belevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 24 11:37:55 PST 2021


tra created this revision.
tra added a reviewer: jlebar.
Herald added subscribers: bixia, yaxunl.
tra requested review of this revision.

According to the standard, instantiating of non-FP complex types is an
unspecified behavior.
http://eel.is/c++draft/complex.numbers.general#2.sentence-1

Non-FP complex types happen to work with libc++, libstdc++ 8 and older, but
break with libstdc++ 9 and newer due to the library not providing implicit
conversion std::complex<FP> ones.


Repository:
  rT test-suite

https://reviews.llvm.org/D97404

Files:
  External/CUDA/complex.cu


Index: External/CUDA/complex.cu
===================================================================
--- External/CUDA/complex.cu
+++ External/CUDA/complex.cu
@@ -22,6 +22,18 @@
 // libstdc++ (compile errors in <complex>).
 #if __cplusplus >= 201103L && (__cplusplus < 201402L || STDLIB_VERSION >= 2014)
 
+// Support for non-fp std::complex is unspecified:
+// http://eel.is/c++draft/complex.numbers.general#2.sentence-1
+#if defined(__GLIBCXX__) && _GLIBCXX_RELEASE >= 9
+// newer versions of libstdc++ does not support implicit conversion from such
+// types.
+#undef TEST_NONFLOAT_COMPLEX
+#else
+// libc++ and older versions of libstdc++ have better support for non-float
+// complex.
+#define TEST_NONFLOAT_COMPLEX 1
+#endif
+
 #include <assert.h>
 #include <complex>
 #include <type_traits>
@@ -121,13 +133,13 @@
     assert(c.imag() == 5);
 
     std::complex<T> c3;
-
+#if TEST_NONFLOAT_COMPLEX
     c3 = c;
     std::complex<int> ic(1, 1);
     c3 += ic;
     assert(c3.real() == 4);
     assert(c3.imag() == 6);
-
+#endif
     c3 = c;
     std::complex<float> fc(1, 1);
     c3 += fc;
@@ -158,13 +170,13 @@
     assert(c.imag() == -5);
 
     std::complex<T> c3;
-
+#if TEST_NONFLOAT_COMPLEX
     c3 = c;
     std::complex<int> ic (1,1);
     c3 -= ic;
     assert(c3.real() == -4);
     assert(c3.imag() == -6);
-
+#endif
     c3 = c;
     std::complex<float> fc (1,1);
     c3 -= fc;
@@ -196,11 +208,13 @@
 
     std::complex<T> c3;
 
+#if TEST_NONFLOAT_COMPLEX
     c3 = c;
     std::complex<int> ic (1,1);
     c3 *= ic;
     assert(c3.real() == -11.5);
     assert(c3.imag() ==   3.5);
+#endif
 
     c3 = c;
     std::complex<float> fc (1,1);
@@ -238,10 +252,12 @@
     std::complex<T> c3;
 
     c3 = c;
+#if TEST_NONFLOAT_COMPLEX
     std::complex<int> ic (1,1);
     c3 /= ic;
     assert(c3.real() ==  0.5);
     assert(c3.imag() == -0.5);
+#endif
 
     c3 = c;
     std::complex<float> fc (1,1);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97404.326160.patch
Type: text/x-patch
Size: 1918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210224/7a696c44/attachment.bin>


More information about the llvm-commits mailing list