Bug 67939 - ICE on using data with negative substring range
Summary: ICE on using data with negative substring range
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 5.2.1
: P3 normal
Target Milestone: 5.3
Assignee: kargls
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-12 16:43 UTC by Gerhard Steinmetz
Modified: 2015-10-29 20:20 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.8.5, 4.9.3, 5.2.0, 6.0
Last reconfirmed: 2015-10-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerhard Steinmetz 2015-10-12 16:43:58 UTC
Depending on compiler options the following codes
show different reactions (sometimes with hanging process).
Depending on environment settings too (e.g. $LANG, $LC_ALL).
All suffer from a negative substring-range (length < -1).


$ cat z1.f90
program p
   character(100) :: x
   data x(998:99) /'ab'/
end


$ cat z2.f90
program p
   character(2) :: x
   data x(:-1) /'ab'/
end


$ gfortran -c z1.f90
z1.f90:3:20:

    data x(998:99) /'ab'/
                    1
Warning: Initialization string starting at (1) was truncated to fit the variable (-898/2)
f951: internal compiler error: Segmentation fault


$ gfortran -c z2.f90
z2.f90:3:17:

    data x(:-1) /'ab'/
                 1
Warning: Initialization string starting at (1) was truncated to fit the variable (-1/2)
*** Error in `/usr/lib64/gcc/x86_64-suse-linux/5/f951': malloc(): memory corruption (fast): 0x0000000001c03420 ***


$ gfortran -g -O0 -Wall -fcheck=all -fno-frontend-optimize -c z2.f90
z2.f90:3:17:

    data x(:-1) /'ab'/
                 1
Warning: Initialization string starting at (1) was truncated to fit the variable (-1/2)
*** Error in `/usr/lib64/gcc/x86_64-suse-linux/5/f951': corrupted double-linked list: 0x00000000036d5db0 ***
Comment 1 Gerhard Steinmetz 2015-10-12 16:45:28 UTC
$ echo $LANG
de_DE.UTF-8
$ echo $LC_ALL

$ cat z3.f90
program p
   character(8) :: x
   data x(3:1) /'abc'/
end


$ gfortran -g -O0 z3.f90
z3.f90:3:17:

    data x(3:1) /'abc'/
                 1
Warning: Initialization string starting at (1) was truncated to fit the variable (-1/3)
f951: malloc.c:2369: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct ...
Comment 2 Dominique d'Humieres 2015-10-13 09:10:49 UTC
On x86_64-apple-darwin14, the tests mostly hang after the warning from 4.8 up to trunk (6.0).
Comment 3 kargls 2015-10-21 19:28:41 UTC
I'm testing a patch.
Comment 4 kargls 2015-10-21 21:40:37 UTC
Author: kargl
Date: Wed Oct 21 21:40:05 2015
New Revision: 229153

URL: https://gcc.gnu.org/viewcvs?rev=229153&root=gcc&view=rev
Log:
2015-10-21  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/67939
	* data.c (create_character_initializer): Deal with zero length string.


2015-10-21  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/67939
	* gfortran.dg/pr67939.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/pr67939.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/data.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 kargls 2015-10-29 20:07:44 UTC
Author: kargl
Date: Thu Oct 29 20:07:13 2015
New Revision: 229555

URL: https://gcc.gnu.org/viewcvs?rev=229555&root=gcc&view=rev
Log:
2015-10-29  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/67939
	* data.c (create_character_initializer): Deal with zero length string.

2015-10-29  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/67939
	* gfortran.dg/pr67939.f90: New test.

Added:
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/pr67939.f90
Modified:
    branches/gcc-5-branch/gcc/fortran/ChangeLog
    branches/gcc-5-branch/gcc/fortran/data.c
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
Comment 6 kargls 2015-10-29 20:20:17 UTC
Fixed on trunk and 5-branch.  Thanks for bug report.