|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Sun Mar 07, 2021 3:35 pm Post subject: Line numbers in warning messages |
|
|
Under certain circumstances, which I cannot quite describe, warning messages issued by the compiler for declared but unused variables, variables given a value but not used later, and variables used before being initialised -- all very useful warnings -- unfortunately contain only the line number of the last line of variable declarations. In most instances, the warning messages contain the line number where a variable is assigned a value or is referenced, which is more useful than the line number of the declarations.
Here is file unusa.f:
Code: | subroutine coeff (jj,numnp,nmat,nsd,vn,thn,chpar,matnum,tdep)
implicit none
integer jj,numnp,nmat,nsd,matnum(numnp)
real vn(numnp), thn(numnp),chpar(nsd*16+3,nmat), tdep(nsd*16+3)
integer jjj, jj1, i, m
real v, vj, thj, tt, ro, dw, dg, xks, xnu, xksp, xnup,
+ xkso, xnuo, xksn, xnun, cc
jjj = (jj - 1)*16
if (jj > 1) jj1 = jjj - 16
do i = numnp, 1, -1
m = matnum(i)
v = vn(i)
if (i /= numnp) then
vj = vn(i+1)
thj = thn(i+1)
endif
ro = chpar(1, m)*exp(tdep(1)*tt)
dw = chpar(4, m)*exp(tdep(4)*tt)
dg = chpar(5, m)*exp(tdep(5)*tt)
xks = chpar(jjj+6, m)*exp(tdep(jjj+6)*tt)
xnu = chpar(jjj+7, m)*exp(tdep(jjj+7)*tt)
if (jj > 1) then
xksp = chpar(jj1+6, m)*exp(tdep(jj1+6)*tt)
xnup = chpar(jj1+7, m)*exp(tdep(jj1+7)*tt)
endif
xkso = chpar(jjj+6, m)*exp(tdep(jjj+6)*tt)
xnuo = chpar(jjj+7, m)*exp(tdep(jjj+7)*tt)
end do
return
end |
The 8.70 compiler reports:
Code: | [FTN95/Win32 Ver. 8.70.0 Copyright (c) Silverfrost Ltd 1993-2020]
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable V has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable VJ has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable THJ has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable TT has been used without being given an initial value
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable RO has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable DW has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable DG has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable XKS has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable XNU has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable XKSP has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable XNUP has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable XKSO has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable XNUO has been given a value but never used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable XKSN has been declared but not used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable XNUN has been declared but not used
WARNING S:\lang\ftn95\unus\unusa.F 7: Variable CC has been declared but not used
NO ERRORS, 16 WARNINGS [<COEFF> FTN95 v8.70.0]
|
My complaint is that all the warnings mention line 7, on which the declarations end.
Last edited by mecej4 on Sun Mar 07, 2021 3:41 pm; edited 2 times in total |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Sun Mar 07, 2021 3:37 pm Post subject: |
|
|
...CONTINUED from previous post (forum limit)...
Here is a slightly different version of the source.
Code: | subroutine Coeff(jj,NumNP,NMat,NSD,thN,ChPar,MatNum,TempN,
+ TempO,TDep,Peclet,Courant,dtMaxC)
dimension thN(NumNP),ChPar(NSD*16+3,NMat),MatNum(NumNP),
+ TempO(NumNP),TempN(NumNP),TDep(NSD*16+3)
jjj=(jj-1)*16
Peclet=0.
Courant=0.
dtMaxC=1.e+30
Tr=293.15
R=8.314
do i=NumNP,1,-1
M=MatNum(i)
ThW=ThN(i)
TT=(TempN(i)+273.15-Tr)/R/(TempN(i)+273.15)/Tr
xKs=ChPar(jjj+6,M)*exp(TDep(jjj+6)*TT)
xNu=ChPar(jjj+7,M)*exp(TDep(jjj+7)*TT)
fExp=ChPar(jjj+8,M)*exp(TDep(jjj+8)*TT)
TTO=(TempO(i)+273.15-Tr)/R/(TempO(i)+273.15)/Tr
xKsO=ChPar(jjj+6,M)*exp(TDep(jjj+6)*TTO)
xNuO=ChPar(jjj+7,M)*exp(TDep(jjj+7)*TTO)
fExpO=ChPar(jjj+8,M)*exp(TDep(jjj+8)*TTO)
if(i.ne.NumNP)TTj=(TempN(i+1)-Tr)/R/(TempN(i+1))/Tr
end do
return
end |
In this case, the compiler gives much more relevant line numbers.
Code: | [FTN95/Win32 Ver. 8.70.0 Copyright (c) Silverfrost Ltd 1993-2020]
WARNING S:\lang\ftn95\unus\unusb.F 16: Variable THW has been given a value but never used
WARNING S:\lang\ftn95\unus\unusb.F 18: Variable XKS has been given a value but never used
WARNING S:\lang\ftn95\unus\unusb.F 19: Variable XNU has been given a value but never used
WARNING S:\lang\ftn95\unus\unusb.F 20: Variable FEXP has been given a value but never used
WARNING S:\lang\ftn95\unus\unusb.F 22: Variable XKSO has been given a value but never used
WARNING S:\lang\ftn95\unus\unusb.F 23: Variable XNUO has been given a value but never used
WARNING S:\lang\ftn95\unus\unusb.F 24: Variable FEXPO has been given a value but never used
WARNING S:\lang\ftn95\unus\unusb.F 25: Variable TTJ has been given a value but never used
NO ERRORS, 8 WARNINGS [<COEFF> FTN95 v8.70.0]
|
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Mon Mar 08, 2021 9:02 am Post subject: |
|
|
mecej4
Thank you for the feedback. I have noted this issue. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Wed Apr 07, 2021 11:28 am Post subject: |
|
|
mecej4
I have had a look at this issue and I can't identify a problem.
The reported line number is only at the end of the declarations because it is the last of the declarations. When a line is continued you get the line number of the last continuation. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Wed Apr 07, 2021 1:14 pm Post subject: |
|
|
Paul, my comments are mainly about four types of errors and how best they could be reported.
1. Unused dummy arguments: display argument list and line numbers of subprogram heading lines.
2. Declared but unused local variables: display declaration line(s) and their line numbers.
3. Variables set but never used: display lines and line numbers wherein assignments are made.
4. Variable used before being set: display lines where references are made to those variables and show the corresponding line numbers.
Perhaps, a shorter example would illustrate how the compiler reports potential bugs as of now, and how I think it could provide more useful information that the programmer could use to rectify the program.
Source file unusc.f:
Code: | subroutine coeff (jj,numnp,nmat,nsd,vn,thn,chpar,matnum,tdep)
implicit none
integer jj,numnp,nmat,nsd,matnum(numnp)
real vn(numnp), thn(numnp),chpar(nsd*16+3,nmat), tdep(nsd*16+3)
integer jjj, jj1, i, m
real v, vj, tt, ro, xnu, xksp
jjj = (jj - 1)*16
if (jj > 1) jj1 = jjj - 16
do i = numnp, 1, -1
m = matnum(i)
v = vn(i)
if (i /= numnp) then
v = vn(i+1)
endif
ro = chpar(1, m)*exp(tdep(1)*tt)
xnu = chpar(jjj+7, m)*exp(tdep(jjj+7)*tt)
end do
xnu = 2*xnu + v - ro
return
end |
For this source file, FTN95 8.71 (recently released) says:
Code: | S:\LANG\FTN95>ftn95 /check unusc.f
[FTN95/Win32 Ver. 8.71.0 Copyright (c) Silverfrost Ltd 1993-2021]
WARNING S:\LANG\FTN95\unusc.F 4: The argument THN has not been used
WARNING S:\LANG\FTN95\unusc.F 5: Variable JJ1 has been given a value but never used
WARNING S:\LANG\FTN95\unusc.F 6: Variable VJ has been declared but not used
WARNING S:\LANG\FTN95\unusc.F 6: Variable TT has been used without being given an initial value
WARNING S:\LANG\FTN95\unusc.F 6: Variable XKSP has been declared but not used
NO ERRORS, 5 WARNINGS [<COEFF> FTN95 v8.71.0] |
This diagnostic output may be contrasted with those from the Lahey-Fujitsu 7.10 and Gfortran 10.2 compilers. LF 7.10 says:
Code: | S:\LANG\FTN95>f95 -c unusc.f
jwd2008i-i "unusc.f", line 4: Dummy argument 'thn' not used in this subprogram.
jwd2006i-i "unusc.f", line 6: 'xksp' is declared but never referenced.
jwd2006i-i "unusc.f", line 6: 'vj' is declared but never referenced.
jwd2004i-i "unusc.f", line 9: 'jj1' is set but never used.
jwd2005i-w "unusc.f", line 17: 'tt' is used but never set.
Encountered 0 errors, 1 warning, 4 informations in file unusc.f |
The line numbers "9" for "set but never used" and "17" for "used but never set" are much more helpful than just the number of the declaration line, "6". Gfortran, too, does better than FTN95 in this regard:
[...continued in my next post... forum limit!]
Last edited by mecej4 on Wed Apr 07, 2021 2:40 pm; edited 2 times in total |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Wed Apr 07, 2021 2:32 pm Post subject: |
|
|
mecej4
Thanks. I will take another look. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Wed Apr 07, 2021 2:39 pm Post subject: |
|
|
[continued from initial post ... forum limit]
Code: | S:\LANG\FTN95>gfortran -Wall -c unusc.f
unusc.f:1:48:
1 | subroutine coeff (jj,numnp,nmat,nsd,vn,thn,chpar,matnum,tdep)
| 1
Warning: Unused dummy argument 'thn' at (1) [-Wunused-dummy-argument]
unusc.f:6:19:
6 | real v, vj, tt, ro, xnu, xksp
| 1
Warning: Unused variable 'vj' declared at (1) [-Wunused-variable]
unusc.f:6:38:
6 | real v, vj, tt, ro, xnu, xksp
| 1
Warning: Unused variable 'xksp' declared at (1) [-Wunused-variable]
unusc.f:17:0:
17 | ro = chpar(1, m)*exp(tdep(1)*tt)
|
Warning: 'tt' may be used uninitialized in this function [-Wmaybe-uninitialized] |
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|