Bug 16336 - ICE with common block in module
Summary: ICE with common block in module
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 16479 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-07-02 20:59 UTC by Erik Schnetter
Modified: 2004-07-12 05:57 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2004-07-02 22:20:56


Attachments
Failing source code (5.06 KB, text/plain)
2004-07-02 21:17 UTC, Erik Schnetter
Details
necessary module source (195 bytes, text/plain)
2004-07-02 21:17 UTC, Erik Schnetter
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Schnetter 2004-07-02 20:59:32 UTC
I use GNU Fortran 95 (GCC 3.5.0 20040702 (experimental)) and compile with 
 
/home/eschnett/gcc/bin/gfortran -ftrapv -march=pentium4 -malign-double -g3 
-Wall -Wshadow -c -o $current_wd/ih_3determinant.F90.o 
$current_wd/ih_3determinant.f90 
 
and receive the error message 
 
/home/eschnett/Calpha/Cactus/configs/einstein-gcc-debug/build/IsolatedHorizon/ih_3determinant.f90:0: 
internal compiler error: Segmentation fault 
Please submit a full bug report, 
with preprocessed source if appropriate.
Comment 1 Andrew Pinski 2004-07-02 21:12:55 UTC
Can you provide the source?
Comment 2 Erik Schnetter 2004-07-02 21:17:33 UTC
Created attachment 6675 [details]
Failing source code
Comment 3 Erik Schnetter 2004-07-02 21:17:57 UTC
Created attachment 6676 [details]
necessary module source
Comment 4 Andrew Pinski 2004-07-02 21:35:26 UTC
hmm, we are trying to print out an error at this point.
Here is the backtrace:
#0  error_string (p=0x73 <Address 0x73 out of bounds>) at /home/gates/pinskia/src/gnu/gcc/src/
gcc/fortran/error.c:109
#1  0x0805b7b0 in error_print (type=0x8463fcd "Error:", format0=Variable "format0" is not available.
) at /home/gates/pinskia/src/gnu/gcc/src/gcc/fortran/error.c:425
#2  0x0805bbbe in gfc_error (format=0x8467948 "COMMON block '%s' at %C has already been USE-
associated")
    at /home/gates/pinskia/src/gnu/gcc/src/gcc/fortran/error.c:596
#3  0x0806f1f6 in gfc_match_common () at /home/gates/pinskia/src/gnu/gcc/src/gcc/fortran/match.
c:2203
#4  0x08075837 in match_word (str=Variable "str" is not available.
) at /home/gates/pinskia/src/gnu/gcc/src/gcc/fortran/parse.c:66
#5  0x08075f2e in decode_statement () at /home/gates/pinskia/src/gnu/gcc/src/gcc/fortran/parse.c:
190
#6  0x08076285 in next_statement () at /home/gates/pinskia/src/gnu/gcc/src/gcc/fortran/parse.c:
353
#7  0x08076bac in parse_spec (st=ST_DATA_DECL) at /home/gates/pinskia/src/gnu/gcc/src/gcc/
fortran/parse.c:1534
#8  0x08077a5c in parse_progunit (st=Variable "st" is not available.
) at /home/gates/pinskia/src/gnu/gcc/src/gcc/fortran/parse.c:2255
#9  0x08078066 in gfc_parse_file () at /home/gates/pinskia/src/gnu/gcc/src/gcc/fortran/parse.c:
2551
#10 0x0808d41a in gfc_be_parse_file (set_yydebug=0) at /home/gates/pinskia/src/gnu/gcc/src/gcc/
fortran/f95-lang.c:264
#11 0x08391098 in toplev_main (argc=115, argv=0xbffec304) at /home/gates/pinskia/src/gnu/gcc/
src/gcc/toplev.c:981
#12 0x420174d9 in __libc_start_main () from /lib/i686/libc.so.6
#13 0x0804b071 in _start ()
Comment 5 Volker Reichelt 2004-07-02 22:20:56 UTC
Here's a reduced example.
It looks like the common COMMON block causes the trouble.

===================================
MODULE bar
  INTEGER :: I
  COMMON /X/I
END MODULE bar

SUBROUTINE foo()
  USE bar
  INTEGER :: J
  COMMON /X/J
END SUBROUTINE foo
===================================
Comment 6 Erik Schnetter 2004-07-03 09:21:16 UTC
In my code, the common block in the module is declared private, so the names 
should not clash. 
 
Comment 7 GCC Commits 2004-07-10 16:26:11 UTC
Subject: Bug 16336

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tobi@gcc.gnu.org	2004-07-10 16:26:06

Modified files:
	gcc/fortran    : ChangeLog match.c 

Log message:
	PR fortran/16336
	* match.c (match_common): Fix error reporting for used common.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&r1=1.109&r2=1.110
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/match.c.diff?cvsroot=gcc&r1=1.15&r2=1.16

Comment 8 Tobias Schlüter 2004-07-10 16:34:39 UTC
This is invalid code: PRIVATE applies only to entities, a common block is no
entity. The segfault is the result of a bug in the call to the error handler.
Patch here: http://gcc.gnu.org/ml/fortran/2004-07/msg00085.html
Comment 9 Erik Schnetter 2004-07-10 17:24:51 UTC
Section 11.2.1, "The USE statement and use association" of the draft of the 
Fortran 2003 standard (J3/04-007) says 
 
"The USE statement provides the means by which a scoping unit accesses [...]" 
 
and then gives a list of what is accessed.  This list does not include common 
block names (except if common blocks are "named data objects", which I do not 
think).  That means that a module should never export common block names. 
 
The standard speaks later in the same section of "accessible entities".  If 
common blocks are not entities, then they should not become accessible. 
 
Comment 10 Tobias Schlüter 2004-07-10 19:48:23 UTC
Given the discussion which followed the patch, I changed this to rejects-valid.
Comment 11 GCC Commits 2004-07-10 22:37:18 UTC
Subject: Bug 16336

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tobi@gcc.gnu.org	2004-07-10 22:37:16

Modified files:
	gcc/fortran    : ChangeLog decl.c gfortran.h match.c match.h 
	                 module.c symbol.c trans-common.c 

Log message:
	PR fortran/16336
	* decl.c (gfc_match_save): Use-associated common block
	doesn't collide.
	* gfortran.h (gfc_common_head): Add new field 'name'.
	Fix typo in comment after #endif.
	* match.c (gfc_get_common): Add new argument from_common,
	mangle name if flag is set, fill in new field in structure
	gfc_common_head.
	(match_common): Set new arg in call to gfc_get_common,
	use-associated common block doesn't collide.
	* match.h (gfc_get_common): Adapt prototype.
	* module.c (load_commons): Set new arg in call to
	gfc_get_common.
	* symbol.c (free_common_tree): New function.
	(gfc_free_namespace): Call new function.
	* trans-common.c (several functions): Remove argument
	'name', use name from gfc_common_head instead.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&r1=1.113&r2=1.114
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/decl.c.diff?cvsroot=gcc&r1=1.17&r2=1.18
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/gfortran.h.diff?cvsroot=gcc&r1=1.18&r2=1.19
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/match.c.diff?cvsroot=gcc&r1=1.16&r2=1.17
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/match.h.diff?cvsroot=gcc&r1=1.8&r2=1.9
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/module.c.diff?cvsroot=gcc&r1=1.10&r2=1.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/symbol.c.diff?cvsroot=gcc&r1=1.9&r2=1.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/trans-common.c.diff?cvsroot=gcc&r1=1.11&r2=1.12

Comment 12 Tobias Schlüter 2004-07-10 22:43:38 UTC
Fixed. I hope Erik agrees this time :-)
Comment 13 GCC Commits 2004-07-10 23:00:02 UTC
Subject: Bug 16336

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tobi@gcc.gnu.org	2004-07-10 22:59:58

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.fortran-torture/execute: common_2.f90 

Log message:
	PR fortran/16336
	* gfortran.fortran-torture/execute/common_2.f90: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3980&r2=1.3981
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.fortran-torture/execute/common_2.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 14 Andrew Pinski 2004-07-12 05:57:23 UTC
*** Bug 16479 has been marked as a duplicate of this bug. ***