https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68743
--- Comment #16 from Steve Kargl <sgk at troutmask dot apl.washington.edu> --- On Sun, Dec 13, 2015 at 05:39:41PM +0000, dave.anglin at bell dot net wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68743 > > --- Comment #15 from dave.anglin at bell dot net --- > On 2015-12-13, at 11:16 AM, kargl at gcc dot gnu.org wrote: > > > What happens if you change -std=gnu11 to -std=c11? > > I will check soon. Possibly, this should be -std=c90 as most > c99 functions are handled as builtins except in strict ISO mode. > There is also -fno-builtin and -fno-builtin-floor, etc. > > > > > It is not clear why you think that this is a libgfortran > > issue. It look likes a target problem (as hpux apparently > > does not have floorf) or a middle-end problem (as gfortran > > is supplying hpux with floorf with perfectly fine C code). > > The floorf implementation in libgfortran is not okay if the compiler is free > to > optimise "(float)floor" to "floorf". This seems to be justified on the basis > that > the floorf key word was reserved in c90 and it was used for the reserved > purpose in c99. But there is vagueness. > If gcc is doing an optimization that changes (float)floor(x) to __builtin_floorf() and then __builtin_floorf() is mapped to libm's floorf(), then that optimization is broken if it is not guarded by a HAVE_FLOORF macro. I'm not an expert on the nuances of the C standard, but it would that a libm could have #define floorf(x) ((float)floor((double)(x)) in math.h. Perhaps, adding a few pessimizations will prevent gcc from doing the optimization. % svn diff c99_functions.c Index: c99_functions.c =================================================================== --- c99_functions.c (revision 231314) +++ c99_functions.c (working copy) @@ -291,7 +291,9 @@ float floorf (float x); float floorf (float x) { - return (float) floor (x); + volatile double retval; + retval = floor((double)x); + return ((float)retval); } #endif or Index: c99_functions.c =================================================================== --- c99_functions.c (revision 231314) +++ c99_functions.c (working copy) @@ -288,10 +288,13 @@ fabsf (float x) #define HAVE_FLOORF 1 float floorf (float x); +static volatile double zero = 0.; float floorf (float x) { - return (float) floor (x); + volatile double retval; + retval = floor((double)(x + zero)); + return ((float)(retval + zero)); } #endif or Index: c99_functions.c =================================================================== --- c99_functions.c (revision 231314) +++ c99_functions.c (working copy) @@ -288,10 +288,16 @@ fabsf (float x) #define HAVE_FLOORF 1 float floorf (float x); +double +_internal_floor(double x) __attribute__ ((noinline)) +{ + return floor (x); +} + float floorf (float x) { - return (float) floor (x); + return ((float)_internal_floor((double)x)); } #endif