I'm getting a very strange behavior with the latest release of the NAG Fortran Compiler Release 6.2(Chiyoda) Build 6214. When using ifort or gfortran is everything ok, and even with NAG Fortran Compiler Release 6.1(Tozai) Build 6136. The following code reproduces the error that I'm getting:
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
Basically, the problem seems to be in the local variable bug
in the procedure proc2
. I'm obtaining the following error report when using 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)
Any suggestions in understanding this behavior? Or perhaps I'm doing something wrong...
Apparently this problem was already solved in patch 6218, as “possible runtime crash for local polymorphic scalar allocatable with no type parameters, if the local variable is not allocated at some time during execution of the routine."