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: [PATCH] Document arithmetic overflow semantics


    In C, it is frequently the case that defining the overflow behavior of
    signed integer in this way makes more optimizations possible.  For one
    thing, it makes addition and multiplication associative.  Without such
    an assumption, you can't turn (a+b)+c into a+(b+c), because the overflows
    might be different.

True, but there are an equal number of simplification that can only be done
if you are allowed to assume that overflow is undefined.

Perhaps an approach might be to say that "we know what overflow
actually does for this operation, but if it occurs, it's undefined
semantics".  That's what we actually *implement* right now and would
give the best of both worlds.  Then there would be a bit that says that,
in this particular operation, the overflow is *not* undefined.


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