public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/98883] New: Module variable not initialized with -finit-real
@ 2021-01-29 11:14 jellby at yahoo dot com
  2021-01-29 11:29 ` [Bug fortran/98883] " dominiq at lps dot ens.fr
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jellby at yahoo dot com @ 2021-01-29 11:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98883

            Bug ID: 98883
           Summary: Module variable not initialized with -finit-real
           Product: gcc
           Version: 7.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jellby at yahoo dot com
  Target Milestone: ---

I use -finit-real=nan hoping to catch some uninitialized variables, but
apparently variables in a module are not obeying this flag and are initialized
to something else (zero?):

!=================================
module foo
implicit none
real :: bar
end module foo

program test
use foo
implicit none
real :: w
write(6,*) w
w = bar
write(6,*) w
end program test
!=================================

$ gfortran -finit-real=nan a.f90 && ./a.out 
              NaN
   0.00000000

So, the first printout shows the unitialized w, correctly set to NaN. The
second printout should be the variable in the module, which is zero for some
reason.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/98883] Module variable not initialized with -finit-real
  2021-01-29 11:14 [Bug fortran/98883] New: Module variable not initialized with -finit-real jellby at yahoo dot com
@ 2021-01-29 11:29 ` dominiq at lps dot ens.fr
  2021-01-29 18:55 ` kargl at gcc dot gnu.org
  2021-01-29 19:04 ` sgk at troutmask dot apl.washington.edu
  2 siblings, 0 replies; 4+ messages in thread
From: dominiq at lps dot ens.fr @ 2021-01-29 11:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98883

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Severity|normal                      |enhancement
   Last reconfirmed|                            |2021-01-29
           Priority|P3                          |P4

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Confirmed.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/98883] Module variable not initialized with -finit-real
  2021-01-29 11:14 [Bug fortran/98883] New: Module variable not initialized with -finit-real jellby at yahoo dot com
  2021-01-29 11:29 ` [Bug fortran/98883] " dominiq at lps dot ens.fr
@ 2021-01-29 18:55 ` kargl at gcc dot gnu.org
  2021-01-29 19:04 ` sgk at troutmask dot apl.washington.edu
  2 siblings, 0 replies; 4+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-01-29 18:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98883

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P4                          |P5
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #2 from kargl at gcc dot gnu.org ---
This bug report should be closed.

Please read the description of option that you are using.

-freal-init=nan applies to **** LOCAL ***** variables.
'bar' is not local to program test, and clearly the option
does not affect variables made available via USE association.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/98883] Module variable not initialized with -finit-real
  2021-01-29 11:14 [Bug fortran/98883] New: Module variable not initialized with -finit-real jellby at yahoo dot com
  2021-01-29 11:29 ` [Bug fortran/98883] " dominiq at lps dot ens.fr
  2021-01-29 18:55 ` kargl at gcc dot gnu.org
@ 2021-01-29 19:04 ` sgk at troutmask dot apl.washington.edu
  2 siblings, 0 replies; 4+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2021-01-29 19:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98883

--- Comment #3 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Fri, Jan 29, 2021 at 06:55:16PM +0000, kargl at gcc dot gnu.org wrote:
> 
> --- Comment #2 from kargl at gcc dot gnu.org ---
> This bug report should be closed.
> 
> Please read the description of option that you are using.
> 
> -freal-init=nan applies to **** LOCAL ***** variables.
> 'bar' is not local to program test, and clearly the option
> does not affect variables made available via USE association.
> 

I'll also point out that 'bar' is local module
to the module, but as it is unused gfortran 
won't initialize it via -finit-real=nan.  If you 
actual use it, it gets initialized.

module foo
  implicit none
  real :: bar
  contains
    subroutine bah
      real boo
      boo = bar ! <-- Sufficient to get bar = NaN
      print *, boo
    end subroutine bah
end module foo

program test
  use foo
  implicit none
  real w
  print *, w
  w = bar
  print *, w
end program test

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-29 19:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-29 11:14 [Bug fortran/98883] New: Module variable not initialized with -finit-real jellby at yahoo dot com
2021-01-29 11:29 ` [Bug fortran/98883] " dominiq at lps dot ens.fr
2021-01-29 18:55 ` kargl at gcc dot gnu.org
2021-01-29 19:04 ` sgk at troutmask dot apl.washington.edu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).