This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix > 2GB Fortran COMMONs


Hi!

The following testcase segfaults on AMD64 (and I guess any other 64-bit
architecture).  The problem is that offset added to a COMMON is
without this patch cast to (int), so upper bits get discarded and the
offset is sign extended.
I'm not sure if usizetype is the best type to use (especially for
consistency with the rest of F77 frontend).  Is there some better one
(it certainly has to be a type with the same width as pointers)?

2003-10-23  Jakub Jelinek  <jakub@redhat.com>

	* com.c (ffecom_sym_transform_): Set tree type of offset
	to usizetype.

--- gcc/f/com.c.jj	2003-10-01 12:10:06.000000000 +0200
+++ gcc/f/com.c	2003-10-22 16:41:47.000000000 +0200
@@ -7919,6 +7919,7 @@ ffecom_sym_transform_ (ffesymbol s)
 	      {
 		ffetargetOffset offset;
 		ffestorag cst;
+		tree toffset;
 
 		cst = ffestorag_parent (st);
 		assert (cst == ffesymbol_storage (cs));
@@ -7935,9 +7936,10 @@ ffecom_sym_transform_ (ffesymbol s)
 			     ffecom_1 (ADDR_EXPR,
 				       build_pointer_type (TREE_TYPE (ct)),
 				       ct));
+		toffset = build_int_2 (offset, 0);
+		TREE_TYPE (toffset) = usizetype;
 		t = ffecom_2 (PLUS_EXPR, TREE_TYPE (t),
-			      t,
-			      build_int_2 (offset, 0));
+			      t, toffset);
 		t = convert (build_pointer_type (type),
 			     t);
 		TREE_CONSTANT (t) = 1;

Testcase:

C { dg-do run { target x86_64-*-* } }
C { dg-options "-m64 -O2 -mcmodel=medium" }

      program test
      parameter ( n3=257)
      common /abc/ a,b
      real*8 a(1024,1024,n3),b(1024,1024,255)
      b(1,100,3)=1.0d0
      a(1,100,3)=1.0d0
      a(1024,1024,n3)=2.d0
      b(1024,1024,255)=3.0
      print *,a(1,100,3),b(1,100,3)
      print *,a(1024,1024,n3),b(1024,1024,255)
      end

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]