This is the mail archive of the gcc@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]

Re: Fortran array indexing on 64-bit targets & snapshot 971023



  In message <9710261322.AA08510@moene.indiv.nluug.nl>you write:
  > > I believe Jim is referring to this:
  > 
  > [ In expand_expr, case ARRAY_REF: ]
  > 
  > [ ... ]
  > 
  >         /* Optimize the special-case of a zero lower bound.
  > 
  >            We convert the low_bound to sizetype to avoid some problems
  >            with constant folding.  (E.g. suppose the lower bound is 1,
  >            and its mode is QI.  Without the conversion,  (ARRAY
  >            +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned  
  > char)1))
  >            +INDEX), which becomes (ARRAY+255+INDEX).  Oops!)
  > 
  >            But sizetype isn't quite right either (especially if
  >            the lowbound is negative).  FIXME */
  > 
  > [ ... ]
  > 
  > The problem is that you cannot be sure that sizetype is signed (see  
  > functions `make_signed_type' and `make_unsigned_type' in  
  > stor-layout.c).
  > 
  > Why it's done this way is beyond me ...
I'd been thinking about this offline and was starting to wonder if
the FIXME really meant that the problem was sizetype was the wrong
type for the conversion and could cause problems.

And the more I think about it, the more I believe that's the real
issue with that code.

For historical reasons, the call into make_[un]signed_type has always
been with the argument "INT_TYPE_SIZE".  And if no value for sizetype
existed, then it was set to the type created by that first call.

[ An aside, I think all the front ends actually assign a real sizetype
  independent of this braindamage in make_[un]signed_type. ]

So, consider what happens with sizeof (int) < sizeof (pointer) and
the lowbound is negative.  We run into the exact same problem
mentioned in the comment.

So it would seem like the comment really means that "sizetype" may
not be the correct type for the conversion.  But that's the closest
global thing we've currently got to the correct type -- though I wonder
why indextype wasn't used.  Oh I see, we convert index to sizetype
just after we fold out the bias.

It's worth noting that having sizetype be smaller than the size
of a pointer is a bad thing -- a few obscure ports still do this
(z8 perhaps?), but I'm not too worried about them since they've
already got some serious problems.

I don't really see any reason to not install this patch.

Comments?

jeff


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