Valgrind 在 Fortran 代码中显示未初始化的变量
我正在 Fortran 应用程序上执行 valgrind(使用 memcheck 工具)。 valgrind 显示以下错误:
==17072== at 0x806C4A2: prove_ (t10_isb.f90:1948)
==17072== by 0x804E9F3: anal1_ (t10_isb.f90:2721)
==17072== by 0x808EECC: MAIN__ (t10_isb.f90:6)
==17072== by 0x808EF14: main (t10_isb.f90:8)
==17072== Uninitialised value was created by a stack allocation
==17072== at 0x805ECDC: relplm_ (t10_isb.f90:3402)
==17072==
==17072==
==17072== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- y
查看源代码,我找不到任何可疑的内容:
这里,在第 1948 行,使用了未初始化的变量,所以我猜它是 ER 或 EZ:
1943 if(NIT.eq.0) then
1944 ER=ER/ekran
1945 EZ=EZ/ekran
1946 end if
1947
1948 EM=DSQRT(ER*ER+EZ*EZ)
1949 ENO=-ER*PK(IEM*9-7)+EZ*PK(IEM*9-5)
1950
1951 IF(PK(IEM*9-8).GE.0.5D0) THEN
1952 ESS=(ER*(PK(IEM*9-4)-F1)+EZ*(PK(IEM*9-6)-F2))
但是,向上调用堆栈,我们可以看到这些变量在调用 PROVE 子例程时直接初始化。
2716
2717 CALL VECMUL(SQ,JJK,CUR,NTP)
2718
2719 ER=0.D0
2720 EZ=0.D0
2721 CALL PROVE(E0,ES1,EN2,TE,TEPR,TEMI,TEMA,RB,ZB,QS,QP,R1P,Z1P,RONAT,ROHQ,RNQ,ZNQ,QNQ,NQ,IM1,IM2,IM3,IM4,IM5,IQQ,NTP,NIT,US,NFR,NTPE,NEM,NR,KEYP,MSYS,ekran,UK,RK,ZK,ER,EZ,F1,F2)
2722
2723 NPPP=NPAOLD+1
2724 DO I=NPPP,NPA
2725 N=I-NPAOLD
我在这里缺少什么?
I'm executing a valgrind (with memcheck tool) on the Fortran application.
Following error is shown by valgrind:
==17072== at 0x806C4A2: prove_ (t10_isb.f90:1948)
==17072== by 0x804E9F3: anal1_ (t10_isb.f90:2721)
==17072== by 0x808EECC: MAIN__ (t10_isb.f90:6)
==17072== by 0x808EF14: main (t10_isb.f90:8)
==17072== Uninitialised value was created by a stack allocation
==17072== at 0x805ECDC: relplm_ (t10_isb.f90:3402)
==17072==
==17072==
==17072== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- y
Looking at the source code, I can't find anything suspicious:
Here, on the line 1948, uninitialized variable is used, so I guess it's either ER or EZ:
1943 if(NIT.eq.0) then
1944 ER=ER/ekran
1945 EZ=EZ/ekran
1946 end if
1947
1948 EM=DSQRT(ER*ER+EZ*EZ)
1949 ENO=-ER*PK(IEM*9-7)+EZ*PK(IEM*9-5)
1950
1951 IF(PK(IEM*9-8).GE.0.5D0) THEN
1952 ESS=(ER*(PK(IEM*9-4)-F1)+EZ*(PK(IEM*9-6)-F2))
However, going up the call stack, we can see that these variables are initialized straight to calling the PROVE subroutine.
2716
2717 CALL VECMUL(SQ,JJK,CUR,NTP)
2718
2719 ER=0.D0
2720 EZ=0.D0
2721 CALL PROVE(E0,ES1,EN2,TE,TEPR,TEMI,TEMA,RB,ZB,QS,QP,R1P,Z1P,RONAT,ROHQ,RNQ,ZNQ,QNQ,NQ,IM1,IM2,IM3,IM4,IM5,IQQ,NTP,NIT,US,NFR,NTPE,NEM,NR,KEYP,MSYS,ekran,UK,RK,ZK,ER,EZ,F1,F2)
2722
2723 NPPP=NPAOLD+1
2724 DO I=NPPP,NPA
2725 N=I-NPAOLD
What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在阅读了 valgrind 和 memcheck 后,事实证明我应该更加注意这一点:
我期望 Valgrind 向我展示第一次从未初始化的读取执行的位置,但是它仅显示何时“统一性”传播到所使用的变量在系统调用或条件跳转中。
我的问题是 ER 变量是通过以下方式初始化的(不是真正的代码,结构类似,但在伪 C 中):
很难将其中一个变量未声明为静态(或根本未声明为静态),鉴于在 FORTRAN77 中,您可以通过变量名称开头的字母隐式声明变量类型。
After reading up on valgrind and memcheck, turns out I should have paid more attention to this bit:
I was expecting Valgrind to show me where the first read from the uninitialized was performed, however it only shows when "unitializedness" propagates to the variable used in syscall or conditional jump.
My issue was that the ER variable was initialized in the following way (not a real code, something similar in structure but in pseudo-C):
It's hard to difficult that one of the variables is not declared static (or explicitly at all), given that in FORTRAN77 you can implicitly declare variable type by the letter its name starts from.