https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67679

            Bug ID: 67679
           Summary: -Wunitialized reports on compiler generated variables
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Joost.VandeVondele at mat dot ethz.ch
  Target Milestone: ---

With gcc 5.2 I see:

> gfortran -c -g -O2 -Wuninitialized -cpp bug.f90
bug.f90:15:0:

       DIMENSION(:, :, :)                     :: work
 ^
Warning: ‘work.dim[2].stride’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
bug.f90:15:0: Warning: ‘work.dim[1].stride’ may be used uninitialized in this
function [-Wmaybe-uninitialized]
bug.f90:15:0: Warning: ‘work.offset’ may be used uninitialized in this function
[-Wmaybe-uninitialized]

where the problem is that compiler generated variables appear in the output. 
(.stride happens x178, .ubound x 111 and .lbound x9 in a CP2K compile).

Some strange forms (not in this testcase) include also :

‘MEM[(integer(kind=4)[2] *)&dim1swp_stat][1]’ may be used uninitialized in this
function

should I try to reduce a testcase for the latter ?

testcase:

> cat bug.f90
MODULE memory_utilities
  INTEGER, PARAMETER :: dp=8, dp_size=8
  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'memory_utilities'
CONTAINS
  SUBROUTINE reallocate_c3(p,lb1_new,ub1_new,lb2_new,ub2_new,lb3_new,ub3_new)
    COMPLEX(KIND=dp), DIMENSION(:, :, :), &
      POINTER                                :: p
    INTEGER, INTENT(IN)                      :: lb1_new, ub1_new, lb2_new, &
                                                ub2_new, lb3_new, ub3_new
    CHARACTER(LEN=*), PARAMETER :: routineN = 'reallocate_c3', &
      routineP = moduleN//':'//routineN
    COMPLEX(KIND=dp), PARAMETER              :: zero = (0.0_dp,0.0_dp)
    INTEGER, PARAMETER                       :: t_size = 2*dp_size
    COMPLEX(KIND=dp), ALLOCATABLE, &
      DIMENSION(:, :, :)                     :: work

    INTEGER :: istat, lb1, lb1_old, lb2, lb2_old, lb3, lb3_old, &
      ub1, ub1_old, ub2, ub2_old, ub3, ub3_old

    IF (ASSOCIATED(p)) THEN
       lb1_old = LBOUND(p,1)
       ub1_old = UBOUND(p,1)
       lb2_old = LBOUND(p,2)
       ub2_old = UBOUND(p,2)
       lb3_old = LBOUND(p,3)
       ub3_old = UBOUND(p,3)
       lb1 = MAX(lb1_new,lb1_old)
       ub1 = MIN(ub1_new,ub1_old)
       lb2 = MAX(lb2_new,lb2_old)
       ub2 = MIN(ub2_new,ub2_old)
       lb3 = MAX(lb3_new,lb3_old)
       ub3 = MIN(ub3_new,ub3_old)
       ALLOCATE (work(lb1:ub1,lb2:ub2,lb3:ub3),STAT=istat)
       IF (istat /= 0) THEN
          CALL stop_memory(routineN,moduleN,__LINE__,&
                           "work",t_size*(ub1-lb1+1)*&
                                         (ub2-lb2+1)*&
                                         (ub3-lb3+1))
       END IF
       work(lb1:ub1,lb2:ub2,lb3:ub3) = p(lb1:ub1,lb2:ub2,lb3:ub3)
       DEALLOCATE (p)
    END IF

    ALLOCATE (p(lb1_new:ub1_new,lb2_new:ub2_new,lb3_new:ub3_new),STAT=istat)
    IF (istat /= 0) THEN
       CALL stop_memory(routineN,moduleN,__LINE__,&
                        "p",t_size*(ub1_new-lb1_new+1)*&
                                   (ub2_new-lb2_new+1)*&
                                   (ub3_new-lb3_new+1))
    END IF
    p(:,:,:) = zero

    IF (ASSOCIATED(p).AND.ALLOCATED(work)) THEN
       p(lb1:ub1,lb2:ub2,lb3:ub3) = work(lb1:ub1,lb2:ub2,lb3:ub3)
       DEALLOCATE (work)
    END IF
  END SUBROUTINE reallocate_c3
END MODULE memory_utilities

Reply via email to