[v2] math/testtgmath2: Fix fabs failure when no long double

Message ID 20210110080241.2003667-1-shorne@gmail.com
State Committed
Commit cc528f9a7e51f769ea79a9c413af417671bcc695
Headers
Series [v2] math/testtgmath2: Fix fabs failure when no long double |

Commit Message

Stafford Horne Jan. 10, 2021, 8:02 a.m. UTC
  I have been testing with GCC trunk and GLIBC master while working on the
OpenRISC port.  This test has been failing with fabs not being called,
This is caused as my architecture is configure with no long double
meaning the two calls are the same:

  TEST (fabs (Vdouble1), double, fabs);
  TEST (fabs (Vldouble1), ldouble, fabs);

Instead of the tgmath calls resolving to fabs and fabsl both calls are
fabs.  Next, do to compiler optimiations the second call is eliminated.
Fix this by invoking the failing TEST with Vldouble2.

Note, I also updated the FAIL message to more clearly show where the
failure happened, so I see:

  FAIL: math/test-tgmath2
  original exit status 1
  wrong function called, fabs (ldouble) failure on line 174

Cc: Joseph Myers <joseph@codesourcery.com>
---
 math/test-tgmath2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Stafford Horne Jan. 13, 2021, 12:04 p.m. UTC | #1
Ping, you may be missed this one.

On Sun, Jan 10, 2021 at 05:02:41PM +0900, Stafford Horne wrote:
> I have been testing with GCC trunk and GLIBC master while working on the
> OpenRISC port.  This test has been failing with fabs not being called,
> This is caused as my architecture is configure with no long double
> meaning the two calls are the same:
> 
>   TEST (fabs (Vdouble1), double, fabs);
>   TEST (fabs (Vldouble1), ldouble, fabs);
> 
> Instead of the tgmath calls resolving to fabs and fabsl both calls are
> fabs.  Next, do to compiler optimiations the second call is eliminated.
> Fix this by invoking the failing TEST with Vldouble2.
> 
> Note, I also updated the FAIL message to more clearly show where the
> failure happened, so I see:
> 
>   FAIL: math/test-tgmath2
>   original exit status 1
>   wrong function called, fabs (ldouble) failure on line 174
> 
> Cc: Joseph Myers <joseph@codesourcery.com>
> ---
>  math/test-tgmath2.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/math/test-tgmath2.c b/math/test-tgmath2.c
> index 14a3453169..b8fb00c566 100644
> --- a/math/test-tgmath2.c
> +++ b/math/test-tgmath2.c
> @@ -122,7 +122,7 @@ int counts[Tlast][C_last];
>        __asm __volatile ("" : : "r" (&texpr));			\
>        if (count != 1 || counts[T##type][C_##fn] != 1)		\
>  	{							\
> -	  FAIL ("wrong function called");			\
> +	  FAIL ("wrong function called, "#fn" ("#type")");	\
>  	  memset (counts, 0, sizeof (counts));			\
>  	}							\
>        count = 0;						\
> @@ -171,7 +171,7 @@ test_fabs (const int Vint4, const long long int Vllong4)
>    TEST (fabs (vcldouble1), ldouble, cabs);
>    TEST (fabs (Vfloat1), float, fabs);
>    TEST (fabs (Vdouble1), double, fabs);
> -  TEST (fabs (Vldouble1), ldouble, fabs);
> +  TEST (fabs (Vldouble2), ldouble, fabs);
>  #ifndef __OPTIMIZE__
>    /* GCC is too smart to optimize these out.  */
>    TEST (fabs (Vint1), double, fabs);
> -- 
> 2.26.2
>
  
Joseph Myers Jan. 13, 2021, 5:52 p.m. UTC | #2
This patch is OK with the missing hyphen in "test-tgmath2" inserted in the 
summary line.

Notes:

* I think the reason this applies to tests of fabs but not tests of other 
functions is that fabs is declared with the __const__ attribute in 
bits/mathcalls.h, so even with -fno-builtin the compiler can remove 
duplicate calls with the same argument.

* The test itself defines ldouble to double if !(LDBL_MANT_DIG > 
DBL_MANT_DIG) so this issue doesn't actually depend on the compiler doing 
any optimizations related to asm remapping of functions in headers.

* Since tgmath.h, when used with compilers older than GCC 8, doesn't 
guarantee actually calling exactly the function name for the type in 
question, only calling some function aliased to it and getting exactly the 
right return type, the test's remapping of ldouble to double helps it 
produce predictable results rather than needing to deal with dependence on 
compiler versions determining whether the double or long double function 
gets called in some cases.
  

Patch

diff --git a/math/test-tgmath2.c b/math/test-tgmath2.c
index 14a3453169..b8fb00c566 100644
--- a/math/test-tgmath2.c
+++ b/math/test-tgmath2.c
@@ -122,7 +122,7 @@  int counts[Tlast][C_last];
       __asm __volatile ("" : : "r" (&texpr));			\
       if (count != 1 || counts[T##type][C_##fn] != 1)		\
 	{							\
-	  FAIL ("wrong function called");			\
+	  FAIL ("wrong function called, "#fn" ("#type")");	\
 	  memset (counts, 0, sizeof (counts));			\
 	}							\
       count = 0;						\
@@ -171,7 +171,7 @@  test_fabs (const int Vint4, const long long int Vllong4)
   TEST (fabs (vcldouble1), ldouble, cabs);
   TEST (fabs (Vfloat1), float, fabs);
   TEST (fabs (Vdouble1), double, fabs);
-  TEST (fabs (Vldouble1), ldouble, fabs);
+  TEST (fabs (Vldouble2), ldouble, fabs);
 #ifndef __OPTIMIZE__
   /* GCC is too smart to optimize these out.  */
   TEST (fabs (Vint1), double, fabs);