[Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0

arnaud02 at users dot sourceforge.net gcc-bugzilla@gcc.gnu.org
Mon Apr 2 15:22:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52835

             Bug #: 52835
           Summary: Incorrect code generated by gfortran 4.7.0
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: arnaud02@users.sourceforge.net


>uname -sm
Linux x86_64
>cat qq.f
      SUBROUTINE QQ2( ISU, ZSPM, RSV, MS )
      INTEGER :: ISU(MS)
      CHARACTER(8) :: ZSPM(MS)
      REAL :: RSV(MS)

      DO IS=1,MS
         ISU(IS)=0
         ZSPM(IS)=' '
         RSV(IS) =0.0
      ENDDO
      END subroutine qq2

      SUBROUTINE QQ()
      INTEGER, ALLOCATABLE :: ISU(:)
      CHARACTER(8), ALLOCATABLE :: ZSPM(:)
      REAL, ALLOCATABLE :: RSV(:)

      ALLOCATE( RSV(3) )
      ALLOCATE( ISU(3) )
      ALLOCATE( ZSPM(3) )
      CALL QQ2( ISU, ZSPM, RSV, 3 )
      write(*,*) '-->',zspm(1)
      END subroutine qq

      program p1
      call qq()
      end program p1
>gfortran470 -O3 -g qq.f -static-libgfortran ; valgrind --track-origins=yes ./a.out
==18017== Memcheck, a memory error detector
==18017== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==18017== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==18017== Command: ./a.out
==18017==
==18017== Syscall param write(buf) points to uninitialised byte(s)
==18017==    at 0x3541CC4150: __write_nocancel (in /lib64/libc-2.5.so)
==18017==    by 0x40981C: raw_write (unix.c:308)
==18017==    by 0x40F4FE: _gfortrani_fbuf_flush (unix.h:56)
==18017==    by 0x405416: _gfortrani_next_record (transfer.c:3397)
==18017==    by 0x405CF8: _gfortran_st_write_done (transfer.c:3592)
==18017==    by 0x401C5B: qq_ (qq.f:22)
==18017==    by 0x401CFC: main (qq.f:26)
==18017==  Address 0x4c2fb44 is 4 bytes inside a block of size 512 alloc'd
==18017==    at 0x4A0776F: malloc (vg_replace_malloc.c:263)
==18017==    by 0x4037B8: _gfortrani_get_mem (memory.c:43)
==18017==    by 0x40F38A: _gfortrani_fbuf_init (fbuf.c:43)
==18017==    by 0x408F89: _gfortrani_init_units (unit.c:585)
==18017==    by 0x403747: init (main.c:226)
==18017==    by 0x4196F5: ??? (in /tmp/arnaud/a.out)
==18017==    by 0x401612: ??? (in /tmp/arnaud/a.out)
==18017==    by 0x9CA212C00000000: ???
==18017==    by 0x419676: __libc_csu_init (in /tmp/arnaud/a.out)
==18017==    by 0x3541C1D84D: (below main) (in /lib64/libc-2.5.so)
==18017==  Uninitialised value was created by a heap allocation
==18017==    at 0x4A0776F: malloc (vg_replace_malloc.c:263)
==18017==    by 0x401BE0: qq_ (qq.f:20)
==18017==    by 0x401CFC: main (qq.f:26)
==18017==
 -->
==18017==
==18017== HEAP SUMMARY:
==18017==     in use at exit: 0 bytes in 0 blocks
==18017==   total heap usage: 20 allocs, 20 frees, 3,878 bytes allocated
==18017==
==18017== All heap blocks were freed -- no leaks are possible
==18017==
==18017== For counts of detected and suppressed errors, rerun with: -v
==18017== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

The test case above demonstrates the problem observed on a large production
system. In qq2, zspm is not set properly to " " as shown by valgrind. This is
taking place only when compiled with "-O3". 

This is a regression with respect to gfortran 4.6.2.



More information about the Gcc-bugs mailing list