Bug 34721 - Output statements fool the -Wuninitialized option
Summary: Output statements fool the -Wuninitialized option
Status: RESOLVED DUPLICATE of bug 19430
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 50331 69937 (view as bug list)
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2008-01-08 23:12 UTC by Dominique d'Humieres
Modified: 2022-08-29 13:16 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-01-10 14:07:44


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominique d'Humieres 2008-01-08 23:12:45 UTC
The following code

subroutine test(a, b, x)
integer :: i, n
real :: a, b, x(:)
if (a==b) n=size(x)
print *, n
do i=1,n
 x(i)=n
end do
end

does not give any warning when compiled with 'gfortran -c -O -Wuninitialized' even if I comment the "if" line. If I comment the "print" line (with or without the "if" one) I get

[ibook-dhum] source/bug% gfc -c -O -Wuninitialized test_uninit.f90
test_uninit.f90: In function 'test':
test_uninit.f90:2: warning: 'n' may be used uninitialized in this function
test_uninit.f90:2: note: 'n' was declared here

as expected.
Comment 1 Manuel López-Ibáñez 2008-01-10 14:07:44 UTC
This is an example that shows that small differences in code lead to quite different SSA representations. Without print we have a PHI node, where one of the operands is the uninitialized value, so we warn. However, with the print statement, we don't generate such PHI node, so we don't warn:

* With the print statement:

  # BLOCK 7, starting at line 5
  # PRED: 5 (false) 6 (fallthru)
  # STORES:  { dt_parm.5D.883 }
  [pr34721.f90 : 5] dt_parm.5D.883.commonD.821.filenameD.743 ={v} &"pr34721.f90"[1]{lb: 1 sz: 1};
  # STORES:  { dt_parm.5D.883 }
  [pr34721.f90 : 5] dt_parm.5D.883.commonD.821.lineD.744 ={v} 5;
  # STORES:  { dt_parm.5D.883 }
  [pr34721.f90 : 5] dt_parm.5D.883.commonD.821.flagsD.741 ={v} 128;
  # STORES:  { dt_parm.5D.883 }
  [pr34721.f90 : 5] dt_parm.5D.883.commonD.821.unitD.742 ={v} 6;
  [pr34721.f90 : 5] _gfortran_st_write (&dt_parm.5D.883);
  [pr34721.f90 : 5] _gfortran_transfer_integer (&dt_parm.5D.883, &nD.872, 4);  <== PASSED BY REFERENCE!!
  [pr34721.f90 : 5] _gfortran_st_write_done (&dt_parm.5D.883);
  # LOADS:  { nD.872 }
  [pr34721.f90 : 6] D.884_31 = nD.872;    <===== NO PHI NODE!!
  [pr34721.f90 : 6] iD.871_32 = 1;
  [pr34721.f90 : 6] if (iD.871_32 <= D.884_31)
    goto <bb 8>;
  else
    goto <bb 9>;
  # SUCC: 8 (true) 9 (false)

* Without the print statement

  # BLOCK 7, starting at line 6
  # PRED: 5 (false) 6 (fallthru)
  # nD.872_2 = PHI <nD.872_26(D)(5), nD.872_32(6)>   <== PHI NODE WITH UNINITIALIZED VALUE!!
  [pr34721.f90 : 6] D.883_33 = nD.872_2;
  [pr34721.f90 : 6] iD.871_34 = 1;
  [pr34721.f90 : 6] if (iD.871_34 <= D.883_33)
    goto <bb 8>;
  else
    goto <bb 9>;
  # SUCC: 8 (true) 9 (false)


I have no idea why "print" generates loads/stores but if the variable is passed by reference to a function, it is very risky to warn, since the function may initialize the variable.
Comment 2 Tobias Burnus 2008-01-10 15:08:22 UTC
Related to PR 31094, PR 31279, and PR 23169.
Comment 3 Dominique d'Humieres 2015-10-18 20:33:33 UTC
*** Bug 50331 has been marked as a duplicate of this bug. ***
Comment 4 Dominique d'Humieres 2016-02-24 09:49:22 UTC
*** Bug 69937 has been marked as a duplicate of this bug. ***
Comment 5 Eric Gallager 2019-02-19 17:23:46 UTC
(In reply to Tobias Burnus from comment #2)
> Related to PR 31094, PR 31279, and PR 23169.

2 of those have since been fixed; does that help this at all?
Comment 6 Richard Biener 2022-08-29 13:16:05 UTC
really duplicate of PR19430

*** This bug has been marked as a duplicate of bug 19430 ***