public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/47307] New: be used uninitialized in this function
@ 2011-01-15 16:12 jszhao at yeah dot net
  2011-01-15 16:42 ` [Bug middle-end/47307] Uninitialized in this function: warning for initialized, no warning for uninitialized burnus at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jszhao at yeah dot net @ 2011-01-15 16:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47307

           Summary: be used uninitialized in this function
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jszhao@yeah.net


Hi there,

With the example code below, gfortran (4.5.0 and 4.6.0) give a strange warning
message with -O2 flag:

> gfortran -Wall -O2 -c readmo.f90
readmo.f90: In function 'readmo':
readmo.f90:4:0: warning: 'convrt' may be used uninitialized in this function

When with -O0, the warning message disappear.

In fact, the array 'lopt' is not initialized in the code, however, the compiler
does not give warning about that. I try the same code with g95, it give a
warning message 'used but not set' about 'lopt'.

Any suggestions or comments? Thanks in advance!

Regards,
Jinsong



subroutine readmo()
!!!! example code readmo.f90 !!!!

   implicit none
   real :: convrt
   integer :: i, iflag, j
   integer, dimension(3,5) :: lopt

   iflag = 0
   do i = 1, 5
      do j = 1, 3
         if ( lopt(j,i) < 0 ) then
            convrt = 1.0
            if ( j > 1 ) convrt = 2.0
            iflag = 1
         endif
      enddo
   enddo
   if ( iflag /= 0 ) then
      do i = 1, 5
         write(6,*) i*convrt
      enddo
   endif

end subroutine readmo


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

* [Bug middle-end/47307] Uninitialized in this function: warning for initialized, no warning for uninitialized
  2011-01-15 16:12 [Bug fortran/47307] New: be used uninitialized in this function jszhao at yeah dot net
@ 2011-01-15 16:42 ` burnus at gcc dot gnu.org
  2011-01-15 22:26 ` dominiq at lps dot ens.fr
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-01-15 16:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47307

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |burnus at gcc dot gnu.org
          Component|fortran                     |middle-end
            Summary|be used uninitialized in    |Uninitialized in this
                   |this function               |function: warning for
                   |                            |initialized, no warning for
                   |                            |uninitialized

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-01-15 16:22:27 UTC ---
Move to middle end. From the dump:

readmo ()
{
  integer(kind=4) lopt[15];
  real(kind=4) convrt;
  [...]
  iflag = 0;
  [...]
    if (lopt[((integer(kind=8)) j + (integer(kind=8)) i * 3) + -4] < 0)
      {
        convrt = 1.0e+0;
        iflag = 1;
      }
  if (iflag != 0)
    ... access convrt ...

Thus, lopt is never set, but not warned for. But convrt is only accessed if it
is set. However, the middle-end (with optimization) only has
  warning: 'convrt' may be used uninitialized in this function


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

* [Bug middle-end/47307] Uninitialized in this function: warning for initialized, no warning for uninitialized
  2011-01-15 16:12 [Bug fortran/47307] New: be used uninitialized in this function jszhao at yeah dot net
  2011-01-15 16:42 ` [Bug middle-end/47307] Uninitialized in this function: warning for initialized, no warning for uninitialized burnus at gcc dot gnu.org
@ 2011-01-15 22:26 ` dominiq at lps dot ens.fr
  2021-04-09 18:10 ` msebor at gcc dot gnu.org
  2022-08-29 13:31 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: dominiq at lps dot ens.fr @ 2011-01-15 22:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47307

--- Comment #2 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2011-01-15 21:50:05 UTC ---
> In fact, the array 'lopt' is not initialized in the code, however, the compiler
> does not give warning about that. I try the same code with g95, it give a
> warning message 'used but not set' about 'lopt'.

Add lopt(1,1) = 0 at the beginning of your code and the g95 warning just
disappears!
So don't rely too much of this kind of warning.

> Any suggestions or comments? Thanks in advance!

Searching bugzilla for "uninitialized" in the subject yields 52 entries for
open pr (not counting those closed as INVALID, DUPLICATE, WONTFIX, ...). I let
you browse the list to check if this pr is a duplicate of one of those (look
for instance to pr24639, my choice is pr27120).

As far as I understand the problem, 
(1) it could be as difficult to solve as running the code itself (think of an
array of 10**9 elements set through a spaghetti code and forgetting to set only
one element). Note this apply also to duplicate initialization (as in Fortran
legalese;-).
(2) the responsibility to use only set variables is on the user, not on the
compiler.


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

* [Bug middle-end/47307] Uninitialized in this function: warning for initialized, no warning for uninitialized
  2011-01-15 16:12 [Bug fortran/47307] New: be used uninitialized in this function jszhao at yeah dot net
  2011-01-15 16:42 ` [Bug middle-end/47307] Uninitialized in this function: warning for initialized, no warning for uninitialized burnus at gcc dot gnu.org
  2011-01-15 22:26 ` dominiq at lps dot ens.fr
@ 2021-04-09 18:10 ` msebor at gcc dot gnu.org
  2022-08-29 13:31 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-09 18:10 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2017-12-30 00:00:00         |2021-4-9
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning has disappeared at -O1 and above.  The expected one for the
uninitialized read from the lopt array is issued now but only at -O0.  With
optimization the read is eliminated.  Given the large number of open bugs for
-Wuninitialized (pr24639) I'm not sure it's worth keeping this open as well.

$ gcc -O0 -S -Wall pr47307.f90 
../pr47307.f90:13:13:

   13 |          if ( lopt(j,i) < 0 ) then
      |             ^
Warning: ‘lopt’ may be used uninitialized [-Wmaybe-uninitialized]
../pr47307.f90:8:34:

    8 |    integer, dimension(3,5) :: lopt
      |                                  ^
note: ‘lopt’ declared here

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

* [Bug middle-end/47307] Uninitialized in this function: warning for initialized, no warning for uninitialized
  2011-01-15 16:12 [Bug fortran/47307] New: be used uninitialized in this function jszhao at yeah dot net
                   ` (2 preceding siblings ...)
  2021-04-09 18:10 ` msebor at gcc dot gnu.org
@ 2022-08-29 13:31 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-08-29 13:31 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
The convrt thing is now working, the lopt diagnostic is given at -O0, the read
is indeed eliminated with optimization.

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

end of thread, other threads:[~2022-08-29 13:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-15 16:12 [Bug fortran/47307] New: be used uninitialized in this function jszhao at yeah dot net
2011-01-15 16:42 ` [Bug middle-end/47307] Uninitialized in this function: warning for initialized, no warning for uninitialized burnus at gcc dot gnu.org
2011-01-15 22:26 ` dominiq at lps dot ens.fr
2021-04-09 18:10 ` msebor at gcc dot gnu.org
2022-08-29 13:31 ` rguenth at gcc dot gnu.org

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).