[patch,fortran] Handle (signed) zeros, infinities and NaNs in some intrinsics

FX fxcoudert@gmail.com
Sat Oct 11 13:15:00 GMT 2014


The attached patch fixes the compile-time simplification of special values (positive and negative zeros, infinities, and NaNs) in intrinsics EXPONENT, FRACTION, RRSPACING, SET_EXPONENT, SPACING. Those are all the intrinsics in the Fortran 2008 standard that say anything about these special values, so it makes sense to fix them. This is the compile-time part of PR 48979 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48979).

Some notes:

  - We’re not technically required to do anything about infinities and NaNs unless IEEE_ARITHMETIC is accessible. My view is that it makes sense, as a quality of implementation issue, to handle them correctly anyway. I’ve done so here for simplification, and intent to do the same later for code generation in trans-intrinsic.c

  - For FRACTION, the 2003 standard says FRACTION(inf) = inf, while Fortran 2008 says FRACTION(inf) = NaN. I agree with Tobias, who said in the PR we shouldn’t emit different code based on -std=f2003/f2008. Instead, we use the Fortran 2008 intepretation here. It makes more sense anyway.

  - While digging into MPFR doc, I realized that the test (mpfr_sgn (x->value.real) == 0) used a few times in simplify.c is not only true for zeros, but also for NaNs! I thus replaced it with mpfr_zero_p (x->value.real). It affects only some (invalid) warnings. For example, before my patch, the code LOG((nan,nan)) would emit an error "Complex argument of LOG cannot be zero”, which makes little sense.


Regtested on x86_64-apple-darwin14. OK to commit?

FX


-------------- next part --------------
A non-text attachment was scrubbed...
Name: intrinsics.ChangeLog
Type: application/octet-stream
Size: 619 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20141011/44844c15/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: intrinsics.diff
Type: application/octet-stream
Size: 7928 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20141011/44844c15/attachment-0001.obj>


More information about the Gcc-patches mailing list