Valgrind 在 Fortran 代码中显示未初始化的变量

发布于 2024-12-08 07:24:00 字数 1428 浏览 0 评论 0原文

我正在 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九公里浅绿 2024-12-15 07:24:00

在阅读了 valgrind 和 memcheck 后,事实证明我应该更加注意这一点:

==17072==  Uninitialised value was created by a stack allocation
==17072==    at 0x805ECDC: relplm_ (t10_isb.f90:3402)

我期望 Valgrind 向我展示第一次从未初始化的读取执行的位置,但是它仅显示何时“统一性”传播到所使用的变量在系统调用或条件跳转中。

我的问题是 ER 变量是通过以下方式初始化的(不是真正的代码,结构类似,但在伪 C 中):

int relplm() {
   static int a11, a12, a13, a21, a31, a32, a33;

   if (value of top-left cell calculated) a11...
   if (value of top-center cell calculated) a12...
   if (value of top-right cell calculated) a13...
   if (value of left cell calculated) a21...
   if (value of right cell calculated) a23...
   if (value of bottom-left cell calculated) a31...
   if (value of bottom-right cell calculated) a32...
   if (value of bottom-right cell calculated) a33...

   if (any of the values changed) er=f(a11,a12,a13,a21,a23,a31,a32,a33)
}

很难将其中一个变量未声明为静态(或根本未声明为静态),鉴于在 FORTRAN77 中,您可以通过变量名称开头的字母隐式声明变量类型。

After reading up on valgrind and memcheck, turns out I should have paid more attention to this bit:

==17072==  Uninitialised value was created by a stack allocation
==17072==    at 0x805ECDC: relplm_ (t10_isb.f90:3402)

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):

int relplm() {
   static int a11, a12, a13, a21, a31, a32, a33;

   if (value of top-left cell calculated) a11...
   if (value of top-center cell calculated) a12...
   if (value of top-right cell calculated) a13...
   if (value of left cell calculated) a21...
   if (value of right cell calculated) a23...
   if (value of bottom-left cell calculated) a31...
   if (value of bottom-right cell calculated) a32...
   if (value of bottom-right cell calculated) a33...

   if (any of the values changed) er=f(a11,a12,a13,a21,a23,a31,a32,a33)
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文