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.
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.
Related to PR 31094, PR 31279, and PR 23169.
*** Bug 50331 has been marked as a duplicate of this bug. ***
*** Bug 69937 has been marked as a duplicate of this bug. ***
(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?
really duplicate of PR19430 *** This bug has been marked as a duplicate of bug 19430 ***