The libgo configury sets special flags to use when compiling the math package, to get more efficient output. Unfortunately, it did not use those flags when testing the math package. This patch fixes that. Fixing that revealed that the flags weren't OK for the current math package, so this patch stops using -funsafe-math-optimizations and starts using -fno-trapping-math, and makes the options more consistent across all targets. This patch also includes https://golang.org/cl/91335, for the master repo, for better testing in gccgo for now. This fixes https://golang.org/issue/23647. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline.
Ian
Index: libgo/Makefile.am =================================================================== --- libgo/Makefile.am (revision 257306) +++ libgo/Makefile.am (working copy) @@ -1138,6 +1138,7 @@ # Pass -ffp-contract=off, or 386-specific options, when building the # math package. MATH_FLAG is defined in configure.ac. math_lo_GOCFLAGS = $(MATH_FLAG) +math_check_GOCFLAGS = $(MATH_FLAG) # Add the generated file runtime_sysinfo.go to the runtime package. extra_go_files_runtime = runtime_sysinfo.go sigtab.go Index: libgo/configure.ac =================================================================== --- libgo/configure.ac (revision 257306) +++ libgo/configure.ac (working copy) @@ -649,8 +649,7 @@ AC_SUBST(STRINGOPS_FLAG) dnl For x86 we want to compile the math library with -mfancy-math-387 -dnl -funsafe-math-optimizations so that we can use the builtin -dnl instructions directly. +dnl so that we can use the builtin instructions directly. AC_CACHE_CHECK([whether compiler supports -mfancy-math-387], [libgo_cv_c_fancymath], [CFLAGS_hold=$CFLAGS @@ -661,10 +660,9 @@ CFLAGS=$CFLAGS_hold]) MATH_FLAG= if test "$libgo_cv_c_fancymath" = yes; then - MATH_FLAG="-mfancy-math-387 -funsafe-math-optimizations -fno-math-errno" -else - MATH_FLAG="-ffp-contract=off" + MATH_FLAG="-mfancy-math-387" fi +MATH_FLAG="${MATH_FLAG} -ffp-contract=off -fno-math-errno -fno-trapping-math" AC_SUBST(MATH_FLAG) CFLAGS_hold=$CFLAGS Index: libgo/go/math/all_test.go =================================================================== --- libgo/go/math/all_test.go (revision 257306) +++ libgo/go/math/all_test.go (working copy) @@ -128,7 +128,7 @@ var ceil = []float64{ 5.0000000000000000e+00, 8.0000000000000000e+00, - 0.0000000000000000e+00, + Copysign(0, -1), -5.0000000000000000e+00, 1.0000000000000000e+01, 3.0000000000000000e+00, @@ -644,7 +644,7 @@ var trunc = []float64{ 4.0000000000000000e+00, 7.0000000000000000e+00, - -0.0000000000000000e+00, + Copysign(0, -1), -5.0000000000000000e+00, 9.0000000000000000e+00, 2.0000000000000000e+00, @@ -2134,7 +2134,7 @@ func TestCeil(t *testing.T) { for i := 0; i < len(vf); i++ { - if f := Ceil(vf[i]); ceil[i] != f { + if f := Ceil(vf[i]); !alike(ceil[i], f) { t.Errorf("Ceil(%g) = %g, want %g", vf[i], f, ceil[i]) } } @@ -2361,7 +2361,7 @@ func TestFloor(t *testing.T) { for i := 0; i < len(vf); i++ { - if f := Floor(vf[i]); floor[i] != f { + if f := Floor(vf[i]); !alike(floor[i], f) { t.Errorf("Floor(%g) = %g, want %g", vf[i], f, floor[i]) } } @@ -2884,7 +2884,7 @@ func TestTrunc(t *testing.T) { for i := 0; i < len(vf); i++ { - if f := Trunc(vf[i]); trunc[i] != f { + if f := Trunc(vf[i]); !alike(trunc[i], f) { t.Errorf("Trunc(%g) = %g, want %g", vf[i], f, trunc[i]) } }