This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libgo patch committed: Make libgo C code more portable


Ian Lance Taylor <iant@google.com> writes:

> This patch to libgo, from Peter Collingbourne, changes some of the C
> code to make it easier to compile libgo with a compiler other than GCC.
> Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
> Committed to mainline.
[...]
> diff -r d73f07d002ef libgo/runtime/print.c
> --- a/libgo/runtime/print.c	Tue May 27 15:00:31 2014 -0700
> +++ b/libgo/runtime/print.c	Wed May 28 16:09:25 2014 -0700
> @@ -2,6 +2,8 @@
>  // Use of this source code is governed by a BSD-style
>  // license that can be found in the LICENSE file.
>  
> +#include <complex.h>
> +#include <math.h>
>  #include <stdarg.h>
>  #include "runtime.h"
>  #include "array.h"
> @@ -174,13 +176,12 @@
>  		gwrite("NaN", 3);
>  		return;
>  	}
> -	i = __builtin_isinf_sign(v);
> -	if(i > 0) {
> -		gwrite("+Inf", 4);
> -		return;
> -	}
> -	if(i < 0) {
> -		gwrite("-Inf", 4);
> +	if(isinf(v)) {
> +		if(signbit(v)) {
> +			gwrite("-Inf", 4);
> +		} else {
> +			gwrite("+Inf", 4);
> +		}
>  		return;
>  	}
>  

This change broke Solaris Go bootstrap:

/vol/gcc/src/hg/trunk/local/libgo/runtime/print.c: In function '__go_print_double':
/vol/gcc/src/hg/trunk/local/libgo/runtime/print.c:200:3: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   if(signbit(v)) {
   ^
cc1: all warnings being treated as errors
make: *** [print.lo] Error 1

It's an issue in the gcc version of signbit in <iso/math_c99.h>,
ultimately:

#undef	signbit
#if defined(__sparc)
#define	signbit(x)	__extension__( \
			{ __typeof(x) __x_s = (x); \
			(int) (*(unsigned *) &__x_s >> 31); })
#elif defined(__i386) || defined(__amd64)
#define	signbit(x)	__extension__( \
			{ __typeof(x) __x_s = (x); \
			(sizeof (__x_s) == sizeof (float) ? \
			(int) (*(unsigned *) &__x_s >> 31) : \
			sizeof (__x_s) == sizeof (double) ? \
			(int) (((unsigned *) &__x_s)[1] >> 31) : \
			(int) (((unsigned short *) &__x_s)[4] >> 15)); })
#endif

Solaris lacks __signbit{f,,l} in libm, like some other Unices do, and
cannot use __builtin_signbit since that is missing in gcc 3.4 still
bundled with Solaris 10 and 11.  I'll probably go for handling this in
fixincludes on mainline, though, where the gcc 3 issue is irrelevant.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]