Bug 20441 - -finit-local-zero is missing from gfortran
Summary: -finit-local-zero is missing from gfortran
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P2 enhancement
Target Milestone: ---
Assignee: Asher Langton
URL:
Keywords:
: 26150 30029 (view as bug list)
Depends on:
Blocks: 31447 33430 19292
  Show dependency treegraph
 
Reported: 2005-03-12 17:11 UTC by Andrew Pinski
Modified: 2007-09-21 02:40 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-06-18 16:23:28


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-03-12 17:11:19 UTC
I was just looking through bugs which have not been touched in 90 days and noticed there was a g77 
bug (PR 18913) which really could not be tested with gfortran because -finit-local-zero is missing.

This option is really only useful for "very" old fortran code.
Comment 1 Dale Ranta 2005-03-14 18:05:24 UTC
This option is needed with most codes decended from main frame codes because
almost all compiliers for the main frames did something like "-finit-local-zero"
by default. The widely used suite of finite element codes from Livermore -
DYNA3D, DYNA2D, NIKE2D, NIKE3D, TOPAZ2D, TOPAZ3D, MAZE, INGRID, ORIAN and TAURUS
all require this option. Going through hundreds of thousands of lines of codes
and trying to patch it to work with out "-finit-local-zero" is hopeless.
Comment 2 Francois-Xavier Coudert 2006-02-07 12:48:10 UTC
*** Bug 26150 has been marked as a duplicate of this bug. ***
Comment 3 tobias.burnus 2006-08-20 20:51:10 UTC
Besides zero initialization (of Real, complex, integer, (what about logical?)), a initialization to a (signaling) NaN (for complex, real) would be also nice to find uninitialized variables.
Comment 4 Andrew Pinski 2006-08-21 01:38:12 UTC
(In reply to comment #3)
> Besides zero initialization (of Real, complex, integer, (what about logical?)),
> a initialization to a (signaling) NaN (for complex, real) would be also nice to
> find uninitialized variables.

Why use -Wuninitialize will warn about those cases (though it can produce some false positives).
Comment 5 Tobias Burnus 2006-11-27 16:02:46 UTC
> > Besides zero initialization [...] a initialization to a (signaling) NaN (for 
> > complex, real) would be also nice to find uninitialized variables.
>
> Why use -Wuninitialize will warn about those cases (though it can produce some
> false positives).

-Wuninitialize does not always work (false negative). Or how do you expect a compiler to find the problem in such cases:

real :: r
call myFunc(r, .true.)
contains
subroutine myFunc(r,l)
 real, intent(inout) :: r
 logical :: l
 if(l) then
   r = r**2
 else
   r = 5
 end if
end subroutine
Comment 6 Andrew Pinski 2006-11-27 16:47:31 UTC
(In reply to comment #5)
> > > Besides zero initialization [...] a initialization to a (signaling) NaN (for 
> > > complex, real) would be also nice to find uninitialized variables.
> >
> > Why use -Wuninitialize will warn about those cases (though it can produce some
> > false positives).
> 
> -Wuninitialize does not always work (false negative). Or how do you expect a
> compiler to find the problem in such cases:

Well in that case r is unused so .. but if you made it used by a write(*,*) r in the program, this becomes another PR with a C example which I cannot find right now.
Comment 7 Thomas Koenig 2006-11-30 22:57:42 UTC
*** Bug 30029 has been marked as a duplicate of this bug. ***
Comment 8 patchapp@dberlin.org 2007-08-17 20:15:35 UTC
Subject: Bug number PR20441

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-08/msg01151.html
Comment 9 Arnaud Desitter 2007-08-20 12:28:52 UTC
Adding -finit-real=nan (http://gcc.gnu.org/ml/fortran/2007-08/msg00408.html) is a real bonus for gfortran. 
Any chance to add "-finit-real=snan" to set "Signalling NaN" ?
A SNaN cannot be the result of any arithmetic operations, hence a good choice for a unset pattern. The NAG compiler uses SNaN when using "-nan".
Comment 10 Asher Langton 2007-08-20 15:07:27 UTC
(In reply to comment #9)
> Adding -finit-real=nan (http://gcc.gnu.org/ml/fortran/2007-08/msg00408.html) is
> a real bonus for gfortran. 
> Any chance to add "-finit-real=snan" to set "Signalling NaN" ?
> A SNaN cannot be the result of any arithmetic operations, hence a good choice
> for a unset pattern. The NAG compiler uses SNaN when using "-nan".

I'd like to add finit-real=snan.  Right now, this requires a bit of a hack, since mpfr (which we use internally for real constants) doesn't distinguish between signaling and quiet NaNs:

http://gcc.gnu.org/ml/fortran/2007-07/msg00512.html
http://websympa.loria.fr/wwsympa/arc/mpfr/2007-07/msg00118.html
Comment 11 Asher Langton 2007-09-21 02:34:26 UTC
Subject: Bug 20441

Author: langton
Date: Fri Sep 21 02:34:14 2007
New Revision: 128643

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128643
Log:
	PR fortran/20441
        * gfortran.h : Add init_local_* enums and init_flag_* flags to
	gfc_option_t.
	* lang.opt: Add -finit-local-zero, -finit-real, -finit-integer,
	-finit-character, and -finit-logical flags.
	* invoke.texi: Document new options.
	* resolve.c (build_init_assign): New function.
	(apply_init_assign): Move part of function into build_init_assign.
	(build_default_init_expr): Build local initializer (-finit-*).
	(apply_default_init_local): Apply local initializer (-finit-*).
	(resolve_fl_variable): Try to add local initializer (-finit-*).
	* options.c (gfc_init_options, gfc_handle_option,
	gfc_post_options): Handle -finit-local-zero, -finit-real,
	-finit-integer, -finit-character, and -finit-logical flags.

	PR fortran/20441
	* gfortran.dg/init_flag_1.f90: New.
	* gfortran.dg/init_flag_2.f90: New.
	* gfortran.dg/init_flag_3.f90: New.
	* gfortran.dg/init_flag_4.f90: New.
	* gfortran.dg/init_flag_5.f90: New.
	* gfortran.dg/init_flag_6.f90: New.
	* gfortran.dg/init_flag_7.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/init_flag_1.f90
    trunk/gcc/testsuite/gfortran.dg/init_flag_2.f90
    trunk/gcc/testsuite/gfortran.dg/init_flag_3.f90
    trunk/gcc/testsuite/gfortran.dg/init_flag_4.f90
    trunk/gcc/testsuite/gfortran.dg/init_flag_5.f90
    trunk/gcc/testsuite/gfortran.dg/init_flag_6.f90
    trunk/gcc/testsuite/gfortran.dg/init_flag_7.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

Comment 12 Asher Langton 2007-09-21 02:40:05 UTC
Fixed on trunk as of revision 128643.