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

            Bug ID: 70994
           Summary: gfortran:  -fcheck=all implied do loop confusing
                    messages
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: physiker at toast2 dot net
  Target Milestone: ---

Compiling the file f.90 with the command line option -fcheck=all active, causes
the "Warning: 'i' may be used uninitialized in this function
[-Wmaybe-uninitialized]". When the -fcheck=all option is removed, there is no
warning. Executing the compiled code causes an error termination.
gfortran-6: At line 8 of file f.f90
Fortran runtime error: Substring out of bounds: upper bound (32767) of 'name'
exceeds string length (22)
gfortran-5: At line 8 of file f.f90
Fortran runtime error: Substring out of bounds: lower bound (0) of 'name' is
less than one

When the variable i is initialized,e.g. i=1, there is no runtime error message. 

f.f90
subroutine f(name)
  implicit none
  character(len=*), intent(in)           :: name
  character, dimension(512)              :: cname
  integer                                :: i 

  cname(1:len_trim(name)+1) = (/ ( name(i:i), i = 1,len_trim(name) ), char(0)
/)
end subroutine f

program t
  implicit none
  character(len=22)           :: name
  name = 'abcdefghijklmnopqr    '
  call f(name)
end program t

LANG=C gfortran-fsf-6 -v -W -Wall -fcheck=all f.f90
Driving: gfortran-fsf-6 -v -W -Wall -fcheck=all f.f90
-mmacosx-version-min=10.9.4 -l gfortran -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran-fsf-6
COLLECT_LTO_WRAPPER=/sw/lib/gcc6/libexec/gcc/x86_64-apple-darwin13.4.0/6.1.0/lto-wrapper
Target: x86_64-apple-darwin13.4.0
Configured with: ../gcc-6.1.0/configure --prefix=/sw --prefix=/sw/lib/gcc6
--mandir=/sw/share/man --infodir=/sw/lib/gcc6/info
--enable-languages=c,c++,fortran,lto,objc,obj-c++,java --with-gmp=/sw
--with-libiconv-prefix=/sw --with-isl=/sw --with-mpc=/sw --with-system-zlib
--program-suffix=-fsf-6
Thread model: posix
gcc version 6.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-Wextra' '-Wall' '-fcheck=all'
'-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
/sw/lib/gcc6/libexec/gcc/x86_64-apple-darwin13.4.0/6.1.0/f951 f.f90 -fPIC
-quiet -dumpbase f.f90 -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase f
-Wextra -Wall -version -fcheck=all -fintrinsic-modules-path
/sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/6.1.0/finclude -o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccD8RIOC.s
GNU Fortran (GCC) version 6.1.0 (x86_64-apple-darwin13.4.0)
        compiled by GNU C version 6.1.0, GMP version 6.1.0, MPFR version 3.1.4,
MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (GCC) version 6.1.0 (x86_64-apple-darwin13.4.0)
        compiled by GNU C version 6.1.0, GMP version 6.1.0, MPFR version 3.1.4,
MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
f.f90:8:0:

   cname(1:len_trim(name)+1) = (/ ( name(i:i), i = 1,len_trim(name) ), char(0)
/)

Warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
COLLECT_GCC_OPTIONS='-v' '-Wextra' '-Wall' '-fcheck=all'
'-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
as -arch x86_64 -force_cpusubtype_ALL -o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc66pKlk.o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccD8RIOC.s
Reading specs from
/sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/6.1.0/../../../libgfortran.spec
rename spec lib to liborig
COLLECT_GCC_OPTIONS='-v' '-Wextra' '-Wall' '-fcheck=all'
'-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
COMPILER_PATH=/sw/lib/gcc6/libexec/gcc/x86_64-apple-darwin13.4.0/6.1.0/:/sw/lib/gcc6/libexec/gcc/x86_64-apple-darwin13.4.0/6.1.0/:/sw/lib/gcc6/libexec/gcc/x86_64-apple-darwin13.4.0/:/sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/6.1.0/:/sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/
LIBRARY_PATH=/sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/6.1.0/:/sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/6.1.0/../../../
COLLECT_GCC_OPTIONS='-v' '-Wextra' '-Wall' '-fcheck=all'
'-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
/sw/lib/gcc6/libexec/gcc/x86_64-apple-darwin13.4.0/6.1.0/collect2 -dynamic
-arch x86_64 -macosx_version_min 10.9.4 -weak_reference_mismatches non-weak -o
a.out -L/sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/6.1.0
-L/sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/6.1.0/../../..
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc66pKlk.o -lgfortran
-no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lgcc_ext.10.5
-lgcc -lSystem -v
collect2 version 6.1.0
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.9.4
-weak_reference_mismatches non-weak -o a.out
-L/sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/6.1.0
-L/sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/6.1.0/../../..
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc66pKlk.o -lgfortran
-no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lgcc_ext.10.5
-lgcc -lSystem -v
@(#)PROGRAM:ld  PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
armv6m armv7m armv7em
Library search paths:
        /sw/lib/gcc6/lib/gcc/x86_64-apple-darwin13.4.0/6.1.0
        /sw/lib/gcc6/lib
        /usr/lib
        /usr/local/lib
Framework search paths:
        /Library/Frameworks/
        /System/Library/Frameworks/
/usr/bin/nm -n /var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc66pKlk.o

Compilation finished at Sat May  7 13:35:36

bash-3.2$ ./a.out
At line 8 of file f.f90
Fortran runtime error: Substring out of bounds: upper bound (32767) of 'name'
exceeds string length (22)

Error termination. Backtrace:
#0  0x104946749
#1  0x104947415
#2  0x1049477ba
#3  0x10493ea2a
#4  0x10493ec44
#5  0x10493ec86

LANG=C gfortran-fsf-5 -v -W -Wall -fcheck=all f.f90
Driving: gfortran-fsf-5 -mmacosx-version-min=10.9.4 -v -W -Wall -fcheck=all
f.f90 -l gfortran -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran-fsf-5
COLLECT_LTO_WRAPPER=/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/5.3.0/lto-wrapper
Target: x86_64-apple-darwin13.4.0
Configured with: ../gcc-5.3.0/configure --prefix=/sw --prefix=/sw/lib/gcc5
--mandir=/sw/share/man --infodir=/sw/lib/gcc5/info
--enable-languages=c,c++,fortran,lto,objc,obj-c++,java --with-gmp=/sw
--with-libiconv-prefix=/sw --with-isl=/sw --with-mpc=/sw --with-system-zlib
--program-suffix=-fsf-5
Thread model: posix
gcc version 5.3.0 (GCC) 
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-Wextra' '-Wall'
'-fcheck=all' '-shared-libgcc' '-mtune=core2'
/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/5.3.0/f951 f.f90 -fPIC
-quiet -dumpbase f.f90 -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase f
-Wextra -Wall -version -fcheck=all -fintrinsic-modules-path
/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/finclude -o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc8Us4wE.s
GNU Fortran (GCC) version 5.3.0 (x86_64-apple-darwin13.4.0)
        compiled by GNU C version 5.3.0, GMP version 6.0.0, MPFR version 3.1.3,
MPC version 1.0.3
warning: GMP header version 6.0.0 differs from library version 6.1.0.
warning: MPFR header version 3.1.3 differs from library version 3.1.4.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (GCC) version 5.3.0 (x86_64-apple-darwin13.4.0)
        compiled by GNU C version 5.3.0, GMP version 6.0.0, MPFR version 3.1.3,
MPC version 1.0.3
warning: GMP header version 6.0.0 differs from library version 6.1.0.
warning: MPFR header version 3.1.3 differs from library version 3.1.4.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
f.f90:8:0:

   cname(1:len_trim(name)+1) = (/ ( name(i:i), i = 1,len_trim(name) ), char(0) 
^
Warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-Wextra' '-Wall'
'-fcheck=all' '-shared-libgcc' '-mtune=core2'
as -arch x86_64 -force_cpusubtype_ALL -o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc9CbUa9.o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc8Us4wE.s
Reading specs from
/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/../../../libgfortran.spec
rename spec lib to liborig
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-Wextra' '-Wall'
'-fcheck=all' '-shared-libgcc' '-mtune=core2'
COMPILER_PATH=/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/5.3.0/:/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/5.3.0/:/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/:/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/:/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/
LIBRARY_PATH=/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/:/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/../../../:/usr/lib/
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-Wextra' '-Wall'
'-fcheck=all' '-shared-libgcc' '-mtune=core2'
/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/5.3.0/collect2 -dynamic
-arch x86_64 -macosx_version_min 10.9.4 -weak_reference_mismatches non-weak -o
a.out -L/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0
-L/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/../../..
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc9CbUa9.o -lgfortran
-no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lgcc_ext.10.5
-lgcc -lSystem -v
collect2 version 5.3.0
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.9.4
-weak_reference_mismatches non-weak -o a.out
-L/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0
-L/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/../../..
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc9CbUa9.o -lgfortran
-no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lgcc_ext.10.5
-lgcc -lSystem -v
@(#)PROGRAM:ld  PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
armv6m armv7m armv7em
Library search paths:
        /sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0
        /sw/lib/gcc5/lib
        /usr/lib
        /usr/local/lib
Framework search paths:
        /Library/Frameworks/
        /System/Library/Frameworks/
/usr/bin/nm -n /var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc9CbUa9.o

bash-3.2$ ./a.out
At line 8 of file f.f90
Fortran runtime error: Substring out of bounds: upper bound (32767) of 'name'
exceeds string length (22)

Error termination. Backtrace:
#0  0x104946749
#1  0x104947415
#2  0x1049477ba
#3  0x10493ea2a
#4  0x10493ec44
#5  0x10493ec86

LANG=C gfortran-fsf-5 -v -W -Wall -fcheck=all f.f90
Driving: gfortran-fsf-5 -mmacosx-version-min=10.9.4 -v -W -Wall -fcheck=all
f.f90 -l gfortran -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran-fsf-5
COLLECT_LTO_WRAPPER=/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/5.3.0/lto-wrapper
Target: x86_64-apple-darwin13.4.0
Configured with: ../gcc-5.3.0/configure --prefix=/sw --prefix=/sw/lib/gcc5
--mandir=/sw/share/man --infodir=/sw/lib/gcc5/info
--enable-languages=c,c++,fortran,lto,objc,obj-c++,java --with-gmp=/sw
--with-libiconv-prefix=/sw --with-isl=/sw --with-mpc=/sw --with-system-zlib
--program-suffix=-fsf-5
Thread model: posix
gcc version 5.3.0 (GCC) 
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-Wextra' '-Wall'
'-fcheck=all' '-shared-libgcc' '-mtune=core2'
/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/5.3.0/f951 f.f90 -fPIC
-quiet -dumpbase f.f90 -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase f
-Wextra -Wall -version -fcheck=all -fintrinsic-modules-path
/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/finclude -o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc8Us4wE.s
GNU Fortran (GCC) version 5.3.0 (x86_64-apple-darwin13.4.0)
        compiled by GNU C version 5.3.0, GMP version 6.0.0, MPFR version 3.1.3,
MPC version 1.0.3
warning: GMP header version 6.0.0 differs from library version 6.1.0.
warning: MPFR header version 3.1.3 differs from library version 3.1.4.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (GCC) version 5.3.0 (x86_64-apple-darwin13.4.0)
        compiled by GNU C version 5.3.0, GMP version 6.0.0, MPFR version 3.1.3,
MPC version 1.0.3
warning: GMP header version 6.0.0 differs from library version 6.1.0.
warning: MPFR header version 3.1.3 differs from library version 3.1.4.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
f.f90:8:0:

   cname(1:len_trim(name)+1) = (/ ( name(i:i), i = 1,len_trim(name) ), char(0) 
^
Warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-Wextra' '-Wall'
'-fcheck=all' '-shared-libgcc' '-mtune=core2'
as -arch x86_64 -force_cpusubtype_ALL -o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc9CbUa9.o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc8Us4wE.s
Reading specs from
/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/../../../libgfortran.spec
rename spec lib to liborig
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-Wextra' '-Wall'
'-fcheck=all' '-shared-libgcc' '-mtune=core2'
COMPILER_PATH=/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/5.3.0/:/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/5.3.0/:/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/:/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/:/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/
LIBRARY_PATH=/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/:/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/../../../:/usr/lib/
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-Wextra' '-Wall'
'-fcheck=all' '-shared-libgcc' '-mtune=core2'
/sw/lib/gcc5/libexec/gcc/x86_64-apple-darwin13.4.0/5.3.0/collect2 -dynamic
-arch x86_64 -macosx_version_min 10.9.4 -weak_reference_mismatches non-weak -o
a.out -L/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0
-L/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/../../..
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc9CbUa9.o -lgfortran
-no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lgcc_ext.10.5
-lgcc -lSystem -v
collect2 version 5.3.0
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.9.4
-weak_reference_mismatches non-weak -o a.out
-L/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0
-L/sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0/../../..
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc9CbUa9.o -lgfortran
-no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lgcc_ext.10.5
-lgcc -lSystem -v
@(#)PROGRAM:ld  PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
armv6m armv7m armv7em
Library search paths:
        /sw/lib/gcc5/lib/gcc/x86_64-apple-darwin13.4.0/5.3.0
        /sw/lib/gcc5/lib
        /usr/lib
        /usr/local/lib
Framework search paths:
        /Library/Frameworks/
        /System/Library/Frameworks/
/usr/bin/nm -n /var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//cc9CbUa9.o

Compilation finished at Sat May  7 13:37:55

bash-3.2$ ./a.out
At line 8 of file f.f90
Fortran runtime error: Substring out of bounds: lower bound (0) of 'name' is
less than one

Reply via email to