This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix > 2GB Fortran COMMONs
On Thu, Oct 23, 2003 at 09:15:42PM +0200, Toon Moene wrote:
> Jakub Jelinek wrote:
>
> > 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)?
>
> ffecom_arrayref_ uses this:
>
> /* Widen integral arithmetic as desired while preserving
> signedness. */
> tree_type = TREE_TYPE (element);
> tree_type_x = tree_type;
> if (tree_type
> && GET_MODE_CLASS (TYPE_MODE (tree_type)) == MODE_INT
> && TYPE_PRECISION (tree_type) < TYPE_PRECISION (sizetype))
> tree_type_x = (TREE_UNSIGNED (tree_type) ? usizetype : ssizetype);
>
> IOW, it checks signedness of the index to decide on the signednes of the
> resulting type to use.
Unlike ffecom_arrayref though, here there is no any type present, as it
is a host constant. It is signed though, so using ssizetype instead
of usizetype might match it better. On most arches it shouldn't make
a difference (as typically *sizetype has the same size as pointers).
Ok to commit (either following version or the original one (which is
s/ssizetype/usizetype/))?
2003-10-30 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-30 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) = ssizetype;
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