Bug 20059

Summary: internal compiler error: Segmentation Fault - For common blocks
Product: gcc Reporter: Dale Ranta <dir>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: gbosilca, gcc-bugs, sje, tobi
Priority: P2 Keywords: ice-on-valid-code
Version: 4.0.0   
Target Milestone: 4.0.1   
Host: powerpc-apple-darwin7.8.0 Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2005-02-18 18:44:20
Bug Depends on: 19387    
Bug Blocks: 19292, 20405    

Description Dale Ranta 2005-02-18 16:26:56 UTC
I get an Segmentation Fault with the Macintosh gfortran from the 20050213
package for this program.


[dranta:~/tests/gfortran] dir% gfortran -c plotz.f
[address=6f6c0004 pc=000140d0]
plotz.f: In function 'plotz':
plotz.f:1: internal compiler error: Segmentation Fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
[dranta:~/tests/gfortran] dir% cat plotz.f
      SUBROUTINE PLOTZ
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      COMMON /HEAD/ HED,P(3)
      CHARACTER HED*80,P*1
      COMMON /ULAB/ LAB(5)
      CHARACTER*80 LAB
      COMMON /IODATA/ DATA(64)
      COMMON /TAPES/ NOUT,NTAPE2,NTAPE3,NTAPE4,NTAPE5,NTAPE6,NTAPE7,
     $ NTAPE8,NTAPE9
      COMMON /CCPOOL/ RMIN,RMAX,ZMIN,ZMAX,IMIN,JMIN,IMAX,JMAX,NFLOP,
     $ HTP,SCALEP,ANGP,CCXMAX,WIDTH
C
        RETURN
      END
Comment 1 Andrew Pinski 2005-02-18 18:44:20 UTC
Confirmed, but note I think this is the same as PR 19387 even though there is no ICE in that bug.
Comment 2 Tobias Schlüter 2005-03-12 23:57:37 UTC
Does this still segfault on powerpc? On i686 I get:
 In file pr20059.f90:10

      COMMON /CCPOOL/ RMIN,RMAX,ZMIN,ZMAX,IMIN,JMIN,IMAX,JMAX,NFLOP, &
                    1
Warning: Padding of 4 bytes required before 'htp' in COMMON 'ccpool' at (1)

Comment 3 Andrew Pinski 2005-03-13 00:06:39 UTC
(In reply to comment #2)
> Does this still segfault on powerpc? On i686 I get:
>  In file pr20059.f90:10
> 
>       COMMON /CCPOOL/ RMIN,RMAX,ZMIN,ZMAX,IMIN,JMIN,IMAX,JMAX,NFLOP, &
>                     1
> Warning: Padding of 4 bytes required before 'htp' in COMMON 'ccpool' at (1)

This is most likely because building a compiler for i686, HWI is 32bits but for PPC, it is 64bit and 
because of PR 19387, we don't deal with HWI in the fortran front-end error/warning functions don't 
understand HWI.  (HWI == Host_Wide_int).
Comment 4 Tobias Schlüter 2005-03-13 00:17:28 UTC
Can you try this patch, Andrew?  The required padding should never overflow 2^32.

2005-03-13  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>

        PR fortran/20059
        * trans-common.c (translate_common): Cast offset/common_segment->offset
        to type int for warning message.

Index: trans-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-common.c,v
retrieving revision 1.24
diff -u -p -r1.24 trans-common.c
--- trans-common.c      12 Mar 2005 21:44:32 -0000      1.24
+++ trans-common.c      13 Mar 2005 00:15:08 -0000
@@ -815,7 +815,7 @@ translate_common (gfc_common_head *commo
                 requirements.  Insert padding immediately before this
                 segment.  */
              gfc_warning ("Padding of %d bytes required before '%s' in "
-                          "COMMON '%s' at %L", offset, s->sym->name,
+                          "COMMON '%s' at %L", (int)offset, s->sym->name,
                           common->name, &common->where);
            }
          else
@@ -841,7 +841,7 @@ translate_common (gfc_common_head *commo
   if (common_segment->offset != 0)
     {
       gfc_warning ("COMMON '%s' at %L requires %d bytes of padding at start",
-                  common->name, &common->where, common_segment->offset);
+                  common->name, &common->where, (int)common_segment->offset);
     }

   create_common (common, common_segment);
Comment 5 Andrew Pinski 2005-03-21 02:25:55 UTC
(In reply to comment #4)
> Can you try this patch, Andrew?  The required padding should never overflow 2^32.

Sorry for not replying sooner, exams got in the way.  But yes this fixes the problem.
Comment 6 Andrew Pinski 2005-04-11 00:38:10 UTC
*** Bug 19387 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2005-04-20 15:08:49 UTC
*** Bug 21125 has been marked as a duplicate of this bug. ***
Comment 8 GCC Commits 2005-04-24 13:51:56 UTC
Subject: Bug 20059

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tobi@gcc.gnu.org	2005-04-24 13:51:39

Modified files:
	gcc/fortran    : ChangeLog trans-common.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: common_5.f 

Log message:
	fortran/
	PR fortran/20059
	* trans-common.c (translate_common): Cast offset and
	common_segment->offset to type int for warning message.
	testsuite/
	PR fortran/20059
	* gfortran.dg/common_5.f: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&r1=1.404&r2=1.405
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/trans-common.c.diff?cvsroot=gcc&r1=1.26&r2=1.27
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5389&r2=1.5390
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/common_5.f.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 9 GCC Commits 2005-04-24 14:00:13 UTC
Subject: Bug 20059

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	tobi@gcc.gnu.org	2005-04-24 13:59:58

Modified files:
	gcc/fortran    : ChangeLog trans-common.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: common_5.f 

Log message:
	fortran/
	PR fortran/20059
	* trans-common.c (translate_common): Cast offset and
	common_segment->offset to type int for warning message.
	
	testsuite/
	PR fortran/20059
	* gfortran.dg/common_5.f: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.335.2.37&r2=1.335.2.38
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/trans-common.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.23.2.3&r2=1.23.2.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.134&r2=1.5084.2.135
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/common_5.f.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 10 Tobias Schlüter 2005-04-24 14:01:30 UTC
Fixed, sorry for the delay.
Comment 11 Andrew Pinski 2005-05-04 19:31:23 UTC
*** Bug 21384 has been marked as a duplicate of this bug. ***