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

            Bug ID: 58579
           Summary: Memory allocation fails when calling character-valued
                    function
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: apbartok at gmail dot com

This is a problem I found with gfortran 4.6.3, 4.7.3, 4.8.0 on

$ uname -a
Linux 3.2.0-29-generic #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 x86_64
x86_64 x86_64 GNU/Linux
$ gfortran -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gfortran-4.8
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.8.0-3ubuntu3~12.04' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin
--with-system-zlib --enable-objc-gc --enable-multiarch --disable-werror
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.0 (Ubuntu/Linaro 4.8.0-3ubuntu3~12.04)

and gfortran 4.7.3 on

$ uname -a
Darwin 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012;
root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64
$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin11/4.7.3/lto-wrapper
Target: x86_64-apple-darwin11
Configured with: ../gcc-4.7.3/configure --prefix=/opt/local
--build=x86_64-apple-darwin11
--enable-languages=c,c++,objc,obj-c++,lto,fortran,java
--libdir=/opt/local/lib/gcc47 --includedir=/opt/local/include/gcc47
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--datarootdir=/opt/local/share/gcc-4.7 --with-libiconv-prefix=/opt/local
--with-local-prefix=/opt/local --with-system-zlib --disable-nls
--program-suffix=-mp-4.7 --with-gxx-include-dir=/opt/local/include/gcc47/c++/
--with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local
--with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl
--disable-cloog-version-check --enable-stage1-checking --disable-multilib
--enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as
--with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar
--with-bugurl=https://trac.macports.org/newticket --disable-ppl-version-check
--with-pkgversion='MacPorts gcc47 4.7.3_1'
Thread model: posix
gcc version 4.7.3 (MacPorts gcc47 4.7.3_1)

I don't think this is a simple stack issue:
$ ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 128297
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) unlimited
cpu time               (seconds, -t) unlimited
max user processes              (-u) 128297
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

The following test case runs fine
$ echo "33554431" | ./a.out

but this one fails
$ echo "33554432" | ./a.out
Operating system error: Cannot allocate memory
Memory allocation failed

compilation:
$ gfortran -g -Wall -Wextra -fno-strict-aliasing -fwrapv -fcheck=all
-fdump-core -fbacktrace test_char_array.f95
(without the "-f" options the code simply returns a segmentation fault.)

code:
$ cat test_char_array.f95
program test_char

   implicit none
   integer :: i

   read*, i
   print*, trim(test(i))

   contains

      function test(i)
         integer, intent(in) :: i
         character(len=i) :: test

         test(1:1) = "A"
      endfunction test

endprogram test_char

Many thanks in advance.
Albert

Reply via email to