Bug 29804 - segfault with -fbounds-check on allocatable derived type components
Summary: segfault with -fbounds-check on allocatable derived type components
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, ice-checking
Depends on:
Blocks: Fortran_bounds_checking
  Show dependency treegraph
 
Reported: 2006-11-11 21:14 UTC by Salvatore Filippone
Modified: 2007-07-12 11:16 UTC (History)
5 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2006-11-11 22:32:34


Attachments
Test case (1.16 KB, text/plain)
2006-11-11 21:15 UTC, Salvatore Filippone
Details
ignore (wrong file) (118 bytes, text/plain)
2006-11-11 22:14 UTC, Tobias Burnus
Details
Reduced test case (217 bytes, text/plain)
2006-11-11 22:31 UTC, Tobias Burnus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Salvatore Filippone 2006-11-11 21:14:55 UTC
The attached code generates a segfault when compiled with -fbounds-check, even if there is no bounds violation nor any other error I can see. (indeed if it's wrong code I'd love to learn why). 
Session log: 
[sfilippo@localhost bugtest]$ gfortran -v 
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.2-20061107/configure --prefix=/usr/local/gcc42 --with-
mpfr-dir=/home/sfilippo/COMPILERS/GFORTRAN/TEMP/mpfr-2.2.0 --with-mpfr=/home/sfi
lippo/COMPILERS/GFORTRAN/TEMP/mpfr --with-gmp-dir=/home/sfilippo/COMPILERS/GFORT
RAN/TEMP/gmp-4.2/ --with-gmp=/home/sfilippo/COMPILERS/GFORTRAN/TEMP/gmp
Thread model: posix
gcc version 4.2.0 20061107 (prerelease)
[sfilippo@localhost bugtest]$ gfortran -o dt_bnd  -ggdb dt_bnd.f90
[sfilippo@localhost bugtest]$ ./dt_bnd
Test case :        1
 
  Description:
 Base
 Type 2 :           2           4           6           8          10          1
2          14          16          18          20          22          24       
   26          28          30          32          34          36          38   
       40
 Multilevel: Level No           2
 Multilevel:            5          10          15          20          25         
 30          35          40          45          50          55          60     
     65          70          75          80          85          90          95 
        100
 
 
Test case :        2
 
  Description:
 Base
 Type 2 :           2           4           6           8          10          1
2          14          16          18          20          22          24       
   26          28          30          32          34          36          38   
       40
 Multilevel: Level No           2
 Multilevel:            5          10          15          20          25         
 30          35          40          45          50          55          60     
     65          70          75          80          85          90          95 
        100
 

[sfilippo@localhost bugtest]$ gfortran -o dt_bnd  -ggdb -fbounds-check dt_bnd.f90
[sfilippo@localhost bugtest]$ ./dt_bnd
Test case :        1
 
Segmentation fault (core dumped)
[sfilippo@localhost bugtest]$ gdb dt_bnd -c core.4828 
GNU gdb Red Hat Linux (6.0post-0.20040223.19rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db lib
rary "/lib/tls/libthread_db.so.1".

Core was generated by `./dt_bnd'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/local/gcc42/lib/libgfortran.so.2...done.
Loaded symbols for /usr/local/gcc42/lib/libgfortran.so.2
Reading symbols from /lib/tls/libm.so.6...done.
Loaded symbols for /lib/tls/libm.so.6
Reading symbols from /usr/local/gcc42/lib/libgcc_s.so.1...done.
Loaded symbols for /usr/local/gcc42/lib/libgcc_s.so.1
Reading symbols from /lib/tls/libc.so.6...done.
Loaded symbols for /lib/tls/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
#0  0x08048c5a in __pp_type__dppset (p=@0x804e6f8, ptype=@0x804bc86, 
    info=@0xbfe053c0, iv=0x0, rs=0x0, rv=0x0, il=0x804d4c4, nl=0x804d4c4, 
    _ptype=2) at dt_bnd.f90:104
104         if (.not.allocated(p%bv(il_)%ipv)) then
Comment 1 Salvatore Filippone 2006-11-11 21:15:54 UTC
Created attachment 12592 [details]
Test case

Very much reduced from a real application code, possibly not minimal yet.
Comment 2 Tobias Burnus 2006-11-11 22:14:11 UTC
Created attachment 12593 [details]
ignore (wrong file)
Comment 3 Tobias Burnus 2006-11-11 22:31:46 UTC
Created attachment 12594 [details]
Reduced test case

Ignore previous attachment that was the wrong file.
Comment 4 Paul Thomas 2006-11-11 22:52:55 UTC
Salvatore,

When I got round to your off-list email, I foun that it was empty.  I was about to contact you.

Paul
Comment 5 Paul Thomas 2006-11-11 23:12:10 UTC
Rather than segfaulting, with Cywin_NT the progam produces

Inconsistent BV for IL>1!          in runtime.

It runs fine withou -founds-check.
Comment 6 Daniel Franke 2007-07-07 19:07:07 UTC
Salvatore, could you please recheck this one? I can not observe any problems, neither on dt_bnd.f90 nor on the reduced testcase. 

$> gfortran-svn -g  -fbounds-check dt_bnd.f90 && ./a.out
[snipped output]

$> valgrind --tool=memcheck --leak-check=full a.out
[...]
==12425== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 1)
==12425== malloc/free: in use at exit: 0 bytes in 0 blocks.
==12425== malloc/free: 24 allocs, 24 frees, 44,703 bytes allocated.

$> gfortran-svn -v
gcc version 4.3.0 20070705 (experimental)


The same holds for:
$> gfortran-4.2 -v
gcc version 4.2.1 20070620 (prerelease)
Comment 7 Thomas Koenig 2007-07-10 13:20:56 UTC
(In reply to comment #6)
> Salvatore, could you please recheck this one? I can not observe any problems,
> neither on dt_bnd.f90 nor on the reduced testcase. 

Neither can I, it seems to have fixed itself.

Should we put it into the test suite to make sure there's no regression?
Comment 8 Jerry DeLisle 2007-07-10 13:43:19 UTC
Subject: Re:  segfault with -fbounds-check on allocatable
 derived type components


Have you looked with valgrind or similar to see if there are errors occurring?

Please definitely put in the testsuite.  There may be something we don't see yet 
going on here.
Comment 9 Francois-Xavier Coudert 2007-07-12 10:59:05 UTC
Subject: Bug 29804

Author: fxcoudert
Date: Thu Jul 12 10:58:49 2007
New Revision: 126578

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126578
Log:
	PR fortran/29804
	* gfortran.dg/alloc_comp_misc_1.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/alloc_comp_misc_1.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 10 Francois-Xavier Coudert 2007-07-12 11:16:42 UTC
I can't see this bug on i686-linux nor x86_64-linux, even with valgrind. I committed the testcase into our testsuite, so that we can see if it ever reappears.