Bug 34721 - Output statements fool the -Wuninitialized option
Summary: Output statements fool the -Wuninitialized option
Status: NEW
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
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2008-01-08 23:12 UTC by Dominique d'Humieres
Modified: 2010-09-02 22:54 UTC (History)
1 user (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.