使用最新版本的NAG Fortran编译器6.2(Chiyoda)内部版本6214时,我得到一个非常奇怪的行为。使用ifort或gfortran时,一切都可以,甚至使用NAG Fortran编译器6.1(Tozai)内部版本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)
对了解这种行为有何建议?也许我做错了事...
答案 0 :(得分:0)
显然,此问题已在补丁6218中解决,因为“本地多态标量可能发生运行时崩溃 如果没有在例程执行期间的某个时间分配局部变量,则可以不分配任何类型参数。”