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]
Other format: [Raw text]

Re: signed is undefined and has been since 1992 (in GCC)







Andrew Pinski wrote on 28/06/2005 08:34:25:

> On Jun 28, 2005, at 1:12 AM, Gabriel Dos Reis wrote:
>
> >  So,
> > please, do refrain from reasoning like "since we did X for Y and Y was
> > undefined behaviour, we should do the same for Z."  "Undefined
> > behaviour" isn't a 0 or 1 thingy, even though it is about computers.
> > You need to evaluate them on case-by-case basis.
Gaby, I am not sure you can do that in a reliable way. You may end up
with different behavior of overflow in the following two cases:
1. for (int i = x ; i <= y ; ++i)
   {
    // this loop can be eliminated - overflow case (y == MAX_INT)
    // is undefined.
    q= s + 5; // moved outside the loop.
   }
2. a = b + c; // modulo

If you treat overflow in case 1 differently than in case 2 then
you get into many inconsistencies and corner cases. What
if the above y results from a+b?  Is the use in loops magically
make a+b not-modulo ? If a+b is still modulo in loops, how
do you block loop optimizations that assume overflow never
happens?

I guess that you can define all that, but the definition is going
complex to the extent that almost nobody will understand.

>
> No, reread what the standard says we don't need to evaluate them case
> by case, that
> is what implementation defined behavior is for.  Maybe this should have
> been
> made that but it was not.  So file a DR report for it instead of saying
> GCC should do
> something when it is already doing what the standard says it can do.

Andrew, if the standard says we "can do" something does not
automatically mean that we should do it just because we can.
If the compiler detects an overflow (constant propagation + flow
analysis), why don't we replace the whole code with
system("rm -rf /") ? We are allowed to do it, and it makes the
executable much smaller.
"can do" != "should do".
Only when there is a visible gain should we equate "can" and "should".
The standard is not a holy scripture, it can be questioned and amended.


I agree with you that a DR should be filed. Filing a DR should silence
these threads for some time.

  Michael


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