https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100440
Bug ID: 100440 Summary: allocated() gives True for unallocated variable Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: dsmith at lmu dot edu Target Milestone: --- A large program that ran correctly on several previous versions of gfortran (and other compilers) failed when I installed version 10 on a 2017 Intel Mac running 10.15.3. gfortran -v Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/usr/local/gfortran/libexec/gcc/x86_64-apple-darwin19/10.2.0/lto-wrapper Target: x86_64-apple-darwin19 Configured with: ../gcc-10.2.0/configure --prefix=/usr/local/gfortran --with-gmp=/Users/fx/devel/gcc/build_package/deps --with-isl=/Users/fx/devel/gcc/build_package/deps --enable-languages=c,c++,fortran,objc,obj-c++ --build=x86_64-apple-darwin19 --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.2.0 (GCC) This program ran correctly under gfortran 6.3, but a similar program using the same set of subroutines failed the same way. That prompted me to upgrade to gfortran 10, but instead things got worse with several other of my programs failing with this error. I have tried to reproduce the error in a small example program, but so far I have not been able to do it. Maybe this description will tell you what the error is, in lieu of the full program. The debug prints check the allocation status of the array within fmmatmul21_fm at the top of the routine. Running under gfortran 10.2 gives: 21 j= 1 allocated(fmmatmul21_fm(j)%mfm%mp) = T size(fmmatmul21_fm(j)%mfm%mp) = 1 At line 133497 of file fmprogram.f95 Fortran runtime error: Attempting to allocate already allocated variable 'fmmatmul21_fm' Other compilers give correct results: 21 j= 1 allocated(fmmatmul21_fm(j)%mfm%mp) = F allocated(fmmatmul21_fm(j)%mfm%mp) = T size(fmmatmul21_fm(j)%mfm%mp) = 12 21 j= 2 allocated(fmmatmul21_fm(j)%mfm%mp) = F allocated(fmmatmul21_fm(j)%mfm%mp) = T size(fmmatmul21_fm(j)%mfm%mp) = 12 ... I don't understand why fmmatmul21_fm should show that it is already allocated when it is basically an uninitialized local variable. It shouldn't matter, but fmmatmul21_fm has not been called earlier in the program. With the deallocate statement enabled, so the allocate statement should then work, I get: 21 j= 1 allocated(fmmatmul21_fm(j)%mfm%mp) = T size(fmmatmul21_fm(j)%mfm%mp) = 1 fmprogram(26871,0x10fa64dc0) malloc: *** error for object 0x5000000000000000: pointer being freed was not allocated fmprogram(26871,0x10fa64dc0) malloc: *** set a breakpoint in malloc_error_break to debug Program received signal SIGABRT: Process abort signal. Here is the function where the error occurs: function fmmatmul21_fm(ma,mb) use fmvals implicit none type (fm) :: ma(:,:),mb(:) type (fm), dimension(size(ma,dim=1)) :: fmmatmul21_fm integer :: j,k,mxsave,nd2,ndsave intent (in) :: ma,mb type(multi), save :: mtlvfm,mulvfm,mvlvfm,mtlv01 if (size(mb) == size(ma,dim=2)) then do j = 1, size(ma,dim=1) print*,'21 j=',j,' allocated(fmmatmul21_fm(j)%mfm%mp) = ', allocated(fmmatmul21_fm(j)%mfm%mp) if(allocated(fmmatmul21_fm(j)%mfm%mp)) print*,' size(fmmatmul21_fm(j)%mfm%mp) = ', size(fmmatmul21_fm(j)%mfm%mp) !deallocate(fmmatmul21_fm(j)%mfm%mp) allocate(fmmatmul21_fm(j)%mfm%mp(ndig+2)) print*,' allocated(fmmatmul21_fm(j)%mfm%mp) = ', allocated(fmmatmul21_fm(j)%mfm%mp) print*,' size(fmmatmul21_fm(j)%mfm%mp) = ', size(fmmatmul21_fm(j)%mfm%mp) enddo ndsave = ndig j = max(ngrd52,2) nd2 = max(2*ndig+j,2) ndig = nd2 mxsave = mxexp do j = 1, size(ma,dim=1) mxexp = mxexp2 call fmi2m(0,mtlvfm) do k = 1, size(mb,dim=1) call fmequ(ma(j,k)%mfm,mulvfm,ndsave,ndig) call fmequ(mb(k)%mfm,mvlvfm,ndsave,ndig) call fmmpy(mulvfm,mvlvfm,mtlv01) call fmadd_r1(mtlvfm,mtlv01) enddo mxexp = mxsave call fmequ(mtlvfm,fmmatmul21_fm(j)%mfm,ndig,ndsave) enddo ndig = ndsave else call fmst2m(' unknown ',mvlvfm) do j = 1, size(ma,dim=1) call fmeq(mvlvfm,fmmatmul21_fm(j)%mfm) enddo endif end function fmmatmul21_fm The context for this subroutine is that it provides the matmul function for matrix times vector for variables of type(fm), which is defined in terms of type(multi) containing allocatable d.p. arrays. type multi real (kind(1.0d0)), allocatable :: mp(:) end type type fm type(multi) :: mfm end type I hope that can give a hint about what might be going wrong. David Smith