On 03/05/19 14:34 +0000, Szabolcs Nagy wrote:
On 03/05/2019 13:08, Jonathan Wakely wrote:
On 03/05/19 11:21 +0000, Szabolcs Nagy wrote:
On 03/05/2019 12:16, Jonathan Wakely wrote:
Hmm, which file in the source tree does the include/cmath symlink in
the build tree point to?

/work/b/build-aarch64-none-elf/obj/gcc2/aarch64-none-elf/libstdc++-v3$ ls -l 
include/cmath
lrwxrwxrwx 1 szabolcs szabolcs 51 May  1 18:06 include/cmath -> 
/work/b/src/gcc/libstdc++-v3/include/c_global/cmath


Oh, I see the problem. <complex> and <cmath> both guard use of
copysign by _GLIBCXX_USE_C99_MATH_TR1 but the test just uses it
unconditionally.

Does the attached patch work?

it fails because copysign takes two arguments,
once that is fixed the test compiles.
thanks.

Doh! I'll commit the working version (attached).


there is still an execution failure, but that's not
related to copysign: proj(i*inf) returns i*inf instead of inf
i haven't figured out why:

/work/b/src/gcc/libstdc++-v3/testsuite/26_numerics/complex/proj.cc:105: void 
test01(): Assertion 'eq( std::proj(c0p) ,
std::complex<double>(pinf, +0.0) )' failed.
FAIL: 26_numerics/complex/proj.cc execution test

If std::copysign isn't avilable then we only provide the generic
std::proj which doesn't support infinities, so all the tests using
positive or negative infinity will give the wrong answer.

The r270759 change doesn't actually use std::copysign, only
__builtin_copysign, but if the compiler doesn't expand that then it
still requires libc to provide copysign. If autoconf decides copysign
isn't available, std::proj doesn't support infinities.

I'm not sure whether to XFAIL the test in that case, or just make the
tests for infinities conditional on the necessary support in libc e.g.

--- a/libstdc++-v3/testsuite/26_numerics/complex/proj.cc
+++ b/libstdc++-v3/testsuite/26_numerics/complex/proj.cc
@@ -101,6 +101,7 @@ test01()
  VERIFY( eq( std::proj(cqq)  , cqq ) );
  VERIFY( eq( std::proj(-cqq) , -cqq ) );

+#ifdef _GLIBCXX_USE_C99_MATH_TR1
  const std::complex<double> c0p(0, pinf);
  VERIFY( eq( std::proj(c0p)  , std::complex<double>(pinf, +0.0) ) );
  VERIFY( eq( std::proj(-c0p) , std::complex<double>(pinf, -0.0) ) );
@@ -164,6 +165,7 @@ test01()
  const std::complex<double> cnp(ninf, pinf);
  VERIFY( eq( std::proj(cnp)  , std::complex<double>(pinf, +0.0) ) );
  VERIFY( eq( std::proj(-cnp) , std::complex<double>(pinf, -0.0) ) );
+#endif
}

void
@@ -215,6 +217,7 @@ test02()
  VERIFY( eq( std::proj(cqq)  , cqq ) );
  VERIFY( eq( std::proj(-cqq) , -cqq ) );

+#ifdef _GLIBCXX_USE_C99_MATH_TR1
  const std::complex<float> c0p(0, pinf);
  VERIFY( eq( std::proj(c0p)  , std::complex<float>(pinf, +0.0) ) );
  VERIFY( eq( std::proj(-c0p) , std::complex<float>(pinf, -0.0) ) );
@@ -278,6 +281,7 @@ test02()
  const std::complex<float> cnp(ninf, pinf);
  VERIFY( eq( std::proj(cnp)  , std::complex<float>(pinf, +0.0) ) );
  VERIFY( eq( std::proj(-cnp) , std::complex<float>(pinf, -0.0) ) );
+#endif
}

void
@@ -329,6 +333,7 @@ test03()
  VERIFY( eq( std::proj(cqq)  , cqq ) );
  VERIFY( eq( std::proj(-cqq) , -cqq ) );

+#ifdef _GLIBCXX_USE_C99_MATH_TR1
  const std::complex<long double> c0p(0, pinf);
  VERIFY( eq( std::proj(c0p)  , std::complex<long double>(pinf, +0.0) ) );
  VERIFY( eq( std::proj(-c0p) , std::complex<long double>(pinf, -0.0) ) );
@@ -392,6 +397,7 @@ test03()
  const std::complex<long double> cnp(ninf, pinf);
  VERIFY( eq( std::proj(cnp)  , std::complex<long double>(pinf, +0.0) ) );
  VERIFY( eq( std::proj(-cnp) , std::complex<long double>(pinf, -0.0) ) );
+#endif
}

int



commit df733472463b868de2c9938e4ea6073105d07ee9
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Fri May 3 20:14:19 2019 +0100

    Fix new testcase to not require std::copysign
    
    Use __builtin_copysign{,f,l} when std::copysign isn't available.
    
            PR libstdc++/61761
            * testsuite/26_numerics/complex/proj.cc: Don't assume <cmath> defines
            std::copysign.

diff --git a/libstdc++-v3/testsuite/26_numerics/complex/proj.cc b/libstdc++-v3/testsuite/26_numerics/complex/proj.cc
index b70ca4c58e9..caf12d25103 100644
--- a/libstdc++-v3/testsuite/26_numerics/complex/proj.cc
+++ b/libstdc++-v3/testsuite/26_numerics/complex/proj.cc
@@ -21,6 +21,22 @@
 #include <limits>
 #include <testsuite_hooks.h>
 
+namespace test
+{
+#ifdef _GLIBCXX_USE_C99_MATH_TR1
+  using std::copysign;
+#else
+  bool copysign(float x, float y)
+  { return __builtin_copysignf(x, y); }
+
+  bool copysign(double x, double y)
+  { return __builtin_copysign(x, y); }
+
+  bool copysign(long double x, long double y)
+  { return __builtin_copysignl(x, y); }
+#endif
+}
+
 template<typename T>
 bool eq(const std::complex<T>& x, const std::complex<T>& y)
 {
@@ -28,9 +44,9 @@ bool eq(const std::complex<T>& x, const std::complex<T>& y)
   bool nan_imags = std::isnan(x.imag()) && std::isnan(y.imag());
 
   bool sign_reals
-    = std::copysign(T(1), x.real()) == std::copysign(T(1), y.real());
+    = test::copysign(T(1), x.real()) == test::copysign(T(1), y.real());
   bool sign_imags
-    = std::copysign(T(1), x.imag()) == std::copysign(T(1), y.imag());
+    = test::copysign(T(1), x.imag()) == test::copysign(T(1), y.imag());
 
   return ((x.real() == y.real() && sign_reals) || nan_reals)
     && ((x.imag() == y.imag() && sign_imags) || nan_imags);

Reply via email to