0

我在使用最新版本的 NAG Fortran Compiler Release 6.2(Chiyoda) Build 6214 时遇到了一个非常奇怪的行为。使用 ifort 或 gfortran 时一切正常,甚至使用 NAG Fortran Compiler Release 6.1(Tozai) Build 6136。以下代码重现了我得到的错误:

module mod
  type :: type1_t
  end type type1_t

  type :: type2_t
  contains
    procedure, nopass :: proc2
  end type type2_t
contains
  subroutine proc2
    class(type1_t), allocatable :: bug
  end subroutine proc2
end module mod

program main
  use mod
  type(type2_t) :: type2
  call type2 % proc2
end program main

基本上,问题似乎出在bug过程中的局部变量上proc2。使用 Valgrind 时,我收到以下错误报告:

==22467== ERROR SUMMARY: 26 errors from 9 contexts (suppressed: 0 from 0)
==22467== 
==22467== 1 errors in context 1 of 9:
==22467== Syscall param write(buf) points to uninitialised byte(s)
==22467==    at 0x5710154: write (write.c:27)
==22467==    by 0x568B1BC: _IO_file_write@@GLIBC_2.2.5 (fileops.c:1203)
==22467==    by 0x568BB2E: new_do_write (fileops.c:457)
==22467==    by 0x568BB2E: _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1277)
==22467==    by 0x567F2AE: fputs (iofputs.c:38)
==22467==    by 0x16E42B: write_insertion (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x16FFC7: rt_message_core.constprop.7 (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x17163D: __NAGf90_rterr (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x121CD8: line_deallocate.isra.2 (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x123E98: __NAGf90_laDeAlloc (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x15FEDB: mod_MP_proc2 (test.f90:12)
==22467==    by 0x15FF54: main (test.f90:18)
==22467==  Address 0x1ffeffe969 is on thread 1's stack
==22467==  in frame #4, created by write_insertion (???:)
==22467==  Uninitialised value was created by a stack allocation
==22467==    at 0x15FBA4: mod_MP_proc2 (test.f90:10)
==22467== 
==22467== 
==22467== 1 errors in context 2 of 9:
==22467== Conditional jump or move depends on uninitialised value(s)
==22467==    at 0x4C32CF9: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22467==    by 0x567F204: fputs (iofputs.c:33)
==22467==    by 0x16E42B: write_insertion (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x16FFC7: rt_message_core.constprop.7 (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x17163D: __NAGf90_rterr (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x121CD8: line_deallocate.isra.2 (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x123E98: __NAGf90_laDeAlloc (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x15FEDB: mod_MP_proc2 (test.f90:12)
==22467==    by 0x15FF54: main (test.f90:18)
==22467==  Uninitialised value was created by a stack allocation
==22467==    at 0x15FBA4: mod_MP_proc2 (test.f90:10)
==22467== 
==22467== 
==22467== 1 errors in context 3 of 9:
==22467== Use of uninitialised value of size 8
==22467==    at 0x121C48: line_deallocate.isra.2 (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x123E98: __NAGf90_laDeAlloc (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x15FEDB: mod_MP_proc2 (test.f90:12)
==22467==    by 0x15FF54: main (test.f90:18)
==22467==  Uninitialised value was created by a stack allocation
==22467==    at 0x15FBA4: mod_MP_proc2 (test.f90:10)
==22467== 
==22467== 
==22467== 1 errors in context 4 of 9:
==22467== Conditional jump or move depends on uninitialised value(s)
==22467==    at 0x127C63: __NAGf90_cdangling_aDeAlloc (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x15FEDB: mod_MP_proc2 (test.f90:12)
==22467==    by 0x15FF54: main (test.f90:18)
==22467==  Uninitialised value was created by a stack allocation
==22467==    at 0x15FBA4: mod_MP_proc2 (test.f90:10)
==22467== 
==22467== 
==22467== 1 errors in context 5 of 9:
==22467== Use of uninitialised value of size 8
==22467==    at 0x15FEA9: mod_MP_proc2 (test.f90:12)
==22467==    by 0x15FF54: main (test.f90:18)
==22467==  Uninitialised value was created by a stack allocation
==22467==    at 0x15FBA4: mod_MP_proc2 (test.f90:10)
==22467== 
==22467== 
==22467== 1 errors in context 6 of 9:
==22467== Use of uninitialised value of size 8
==22467==    at 0x15FE96: mod_MP_proc2 (test.f90:12)
==22467==    by 0x15FF54: main (test.f90:18)
==22467==  Uninitialised value was created by a stack allocation
==22467==    at 0x15FBA4: mod_MP_proc2 (test.f90:10)
==22467== 
==22467== 
==22467== 1 errors in context 7 of 9:
==22467== Conditional jump or move depends on uninitialised value(s)
==22467==    at 0x15FE90: mod_MP_proc2 (test.f90:12)
==22467==    by 0x15FF54: main (test.f90:18)
==22467==  Uninitialised value was created by a stack allocation
==22467==    at 0x15FBA4: mod_MP_proc2 (test.f90:10)
==22467== 
==22467== 
==22467== 9 errors in context 8 of 9:
==22467== Conditional jump or move depends on uninitialised value(s)
==22467==    at 0x4C32D08: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22467==    by 0x567F204: fputs (iofputs.c:33)
==22467==    by 0x16E42B: write_insertion (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x16FFC7: rt_message_core.constprop.7 (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x17163D: __NAGf90_rterr (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x121CD8: line_deallocate.isra.2 (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x123E98: __NAGf90_laDeAlloc (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x15FEDB: mod_MP_proc2 (test.f90:12)
==22467==    by 0x15FF54: main (test.f90:18)
==22467==  Uninitialised value was created by a stack allocation
==22467==    at 0x15FBA4: mod_MP_proc2 (test.f90:10)
==22467== 
==22467== 
==22467== 10 errors in context 9 of 9:
==22467== Conditional jump or move depends on uninitialised value(s)
==22467==    at 0x16EAD1: write_insertion (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x16FFC7: rt_message_core.constprop.7 (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x17163D: __NAGf90_rterr (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x121CD8: line_deallocate.isra.2 (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x123E98: __NAGf90_laDeAlloc (in /home/rcarvalho/Desktop/nagdebug/a.out)
==22467==    by 0x15FEDB: mod_MP_proc2 (test.f90:12)
==22467==    by 0x15FF54: main (test.f90:18)
==22467==  Uninitialised value was created by a stack allocation
==22467==    at 0x15FBA4: mod_MP_proc2 (test.f90:10)
==22467== 
==22467== ERROR SUMMARY: 26 errors from 9 contexts (suppressed: 0 from 0)
Aborted (core dumped)

在理解这种行为方面有什么建议吗?或者也许我做错了什么......

4

1 回答 1

0

显然,这个问题已经在补丁 6218 中解决,因为“如果在例程执行期间的某个时间没有分配局部变量,则本地多态标量可能会在没有类型参数的情况下分配运行时崩溃。”

于 2018-10-05T21:01:52.170 回答