Suggested by ISO/IEC Project 22.24772 "Guidance for Avoiding Vulnerabilities through Language Selection and Use" (see links at http://gcc.gnu.org/wiki/GFortranStandards) From the Fortran appendix (draft at http://grouper.ieee.org/groups/plv/DocLog/400-499/400-419/22-WG23-N-0410/n0410.pdf) "Fortran.5 Floating-point Arithmetic [PFL] ... "Fortran.5.2 Guidance to Fortran Users" ... "* Do not create a logical value from a test for equality or inequality between two floating-point expressions. Use compiler options where available to detect such a usage" gfortran doesn't have such a warning.
Sounds doable. I'll give it a shot.
(In reply to comment #1) > Sounds doable. > I'll give it a shot. Thanks. I think it can help to find some real-world issues, even if comparisons such as "a == 0.0" are generally safe. (In reply to comment #0) > Suggested by ISO/IEC Project 22.24772 "Guidance for Avoiding Vulnerabilities > through Language Selection and Use" (see links at > http://gcc.gnu.org/wiki/GFortranStandards) > > From the Fortran appendix (draft at Wrong link (that's the current 2nd-version draft of the TR, still the Fortran part). The Fortran link is: ftp://ftp.nag.co.uk/sc22wg5/N1901-N1950/N1929.pdf The issue is also mentioned in "Fortran.58 Implications for Standardization" under "Future standardization efforts should consider:" "Requiring that processors have the ability to detect and report the occurrence within a submitted program unit of tests for equality between two objects of type real or complex."
Author: tkoenig Date: Sun Aug 19 15:05:41 2012 New Revision: 190516 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190516 Log: 2012-08-19 Thomas König <tkoenig@gcc.gnu.org> PR fortran/54298 * gfortran.h (struct gfc_option_t): Add warn_compare_reals. * lang.opt: Add Wcompare-reals. * invoke.texi: Document -Wcompare-reals. * resolve.c (resolve_operator): If -Wcompare-reals is in effect, warn about equality/inequality comparisions for REAL and COMPLEX. * options.c (gfc_init_options): Set warn_compare_reals. (set_Wall): Include warn_compare_reals in Wall. (gfc_handle_option): Handle Wcompare_reals. 2012-08-19 Thomas König <tkoenig@gcc.gnu.org> PR fortran/54298 * gfortran.dg/real_compare_1.f90: New test case. * gfortran.dg/bessel_5.f90 Add -Wno-compare-reals to options. Added: trunk/gcc/testsuite/gfortran.dg/real_compare_1.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/invoke.texi trunk/gcc/fortran/lang.opt trunk/gcc/fortran/options.c trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/bessel_5.f90
Fixed on trunk, closing.