From: jhbrown@ai.mit.edu (Jeremy H. Brown)
Date: Sun, 30 Jun 1996 18:25:47 -0400
Subject: Re: libuseful bug in folding pointers: new bug report
Message-Id: <199606302225.SAA17414@tarkin.ai.mit.edu>



I'll try to answer this again, since my mail went into the void last time:

   From: Chris Wilson <cwilson@cs.stanford.edu>

   > Now, on to the new problem:  gcc does this sort of thing all over:
   > 
   > typedef int *rtx;
   > rtx foo() {
   >   return (rtx) -1;
   > }
   > 
   > However, this causes badness:
   > 
   > s2c:Warning: constant too large for type
   > 
   > extern int *foo()
   >   {
   >     return 4294967295;
   >   }
   > 
   > -------------

   I'm not quite clear on why this is bad.  SUIF knows there are 32-bits
   in a pointer, so it is using (2^32)-1 as the result of casting a -1 to
   a pointer type.  Just like casting -1 to ``unsigned''.

So, in fact, you are correct -- this is not intrinsically a bad thing
for SUIF to do.  The problem is the way it does it, specifically:

1) when porky does the folding, it complains about an overflow error
when it makes the conversion, even though the conversion is correct.
I thought this was the actual source of my crashes, but it's not --
it's just an annoyance.  The real problem is here:

2) when s2c attempts to emit the code, it crashes with the constant
too large error, which it just shouldn't do -- 4294967295 fits in a
32-bit constant.  (I got the code output above using the -pseudo flag)


I haven't worried about fixing 1, since it's just a warning; 2 I came
up with a fix for:

In ldc.cc, the function ldc_tree doesn't handle pointers as a special
case in the int/extended_int case of the switch statement that makes
up most of the procedure.  I just inserted this code around line 251:

            if (the_type->op() == TYPE_PTR) 
              return new ctree(ctree_intconst, type_signed, value_ii);

which seems to emit the correct code without warnings or crashes.  (I
don't really understand what it does; I just figured out what the
-pseudo flag was causing to happen, and made it a specific case.)

Jeremy