public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/58579] New: Memory allocation fails when calling character-valued function
@ 2013-09-30 14:17 apbartok at gmail dot com
2013-09-30 21:01 ` [Bug fortran/58579] " burnus at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: apbartok at gmail dot com @ 2013-09-30 14:17 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/58579] Memory allocation fails when calling character-valued function
2013-09-30 14:17 [Bug fortran/58579] New: Memory allocation fails when calling character-valued function apbartok at gmail dot com
@ 2013-09-30 21:01 ` burnus at gcc dot gnu.org
2013-09-30 21:20 ` burnus at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-09-30 21:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58579
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
CC| |burnus at gcc dot gnu.org
Known to fail| |4.8.1, 4.9.0
--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> ---
The generated code (-fdump-tree-original) looks odd:
D.1887 = &i;
D.1888 = *D.1887;
D.1890 = MAX_EXPR <D.1888, 0> * 64;
D.1891 = (void * restrict) __builtin_malloc (MAX_EXPR <(unsigned long)
D.1890, 1>);
Why is there the multiplication by 64? We have a kind=1 character, i.e. one
should have multiplied by 1 (byte). Random guess: That's the bit size of a
pointer.
(That it fails with that multiplication is clear: gfortran uses a (signed)
32bit variable for the string length - and 33554432 * 64 == 2**31 - but
(2**31-1) is the largest positive 32bit integer.)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/58579] Memory allocation fails when calling character-valued function
2013-09-30 14:17 [Bug fortran/58579] New: Memory allocation fails when calling character-valued function apbartok at gmail dot com
2013-09-30 21:01 ` [Bug fortran/58579] " burnus at gcc dot gnu.org
@ 2013-09-30 21:20 ` burnus at gcc dot gnu.org
2013-10-01 21:00 ` burnus at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-09-30 21:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58579
--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Completely untested draft patch
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -2355,11 +2355,13 @@ gfc_conv_string_tmp (gfc_se * se, tree type, tree len)
{
/* Allocate a temporary to hold the result. */
var = gfc_create_var (type, "pstr");
+ tmp = TYPE_SIZE_UNIT (get_element_type (type));
+ tmp = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
+ fold_convert (size_type_node, len),
+ fold_convert (size_type_node, tmp));
tmp = gfc_call_malloc (&se->pre, type,
fold_build2_loc (input_location, MULT_EXPR,
- TREE_TYPE (len), len,
- fold_convert (TREE_TYPE (len),
- TYPE_SIZE
(type))));
+ size_type_node, len, tmp);
gfc_add_modify (&se->pre, var, tmp);
/* Free the temporary afterwards. */
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/58579] Memory allocation fails when calling character-valued function
2013-09-30 14:17 [Bug fortran/58579] New: Memory allocation fails when calling character-valued function apbartok at gmail dot com
2013-09-30 21:01 ` [Bug fortran/58579] " burnus at gcc dot gnu.org
2013-09-30 21:20 ` burnus at gcc dot gnu.org
@ 2013-10-01 21:00 ` burnus at gcc dot gnu.org
2013-10-01 21:01 ` burnus at gcc dot gnu.org
2013-10-01 21:57 ` apbartok at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-10-01 21:00 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58579
--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Author: burnus
Date: Tue Oct 1 21:00:17 2013
New Revision: 203088
URL: http://gcc.gnu.org/viewcvs?rev=203088&root=gcc&view=rev
Log:
2013-10-01 Tobias Burnus <burnus@net-b.de>
PR fortran/58579
* trans-expr.c (gfc_conv_string_tmp): Correctly obtain
the byte size of a single character.
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/trans-expr.c
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/58579] Memory allocation fails when calling character-valued function
2013-09-30 14:17 [Bug fortran/58579] New: Memory allocation fails when calling character-valued function apbartok at gmail dot com
` (2 preceding siblings ...)
2013-10-01 21:00 ` burnus at gcc dot gnu.org
@ 2013-10-01 21:01 ` burnus at gcc dot gnu.org
2013-10-01 21:57 ` apbartok at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-10-01 21:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58579
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization, patch
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> ---
FIXED on the trunk for GCC 4.9.
Thanks for the report!
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/58579] Memory allocation fails when calling character-valued function
2013-09-30 14:17 [Bug fortran/58579] New: Memory allocation fails when calling character-valued function apbartok at gmail dot com
` (3 preceding siblings ...)
2013-10-01 21:01 ` burnus at gcc dot gnu.org
@ 2013-10-01 21:57 ` apbartok at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: apbartok at gmail dot com @ 2013-10-01 21:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58579
--- Comment #6 from Albert <apbartok at gmail dot com> ---
Thanks for the very quick reply and also for the fix!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-10-01 21:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-30 14:17 [Bug fortran/58579] New: Memory allocation fails when calling character-valued function apbartok at gmail dot com
2013-09-30 21:01 ` [Bug fortran/58579] " burnus at gcc dot gnu.org
2013-09-30 21:20 ` burnus at gcc dot gnu.org
2013-10-01 21:00 ` burnus at gcc dot gnu.org
2013-10-01 21:01 ` burnus at gcc dot gnu.org
2013-10-01 21:57 ` apbartok at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).