Paul Eggert <[EMAIL PROTECTED]> writes: > Mark Mitchell <[EMAIL PROTECTED]> writes: >> it sounds like that would eliminate most of the problem. Certainly, >> making -INT_MIN evaluate to INT_MIN, when expressed like that, is an >> easy thing to do; that's just a guarantee about constant folding. > > Well, no, just to clarify: the GCC code in question actually computed > "- x", and relied on the fact that the result was INT_MIN if x (an > unknown integer) happened to be INT_MIN. Also, now that I'm thinking > about it, some the Unix v7 atoi() implementation relied on "x + 8" > evaluating to INT_MIN when x happened to be (INT_MAX - 7). These are > the usual kind of assumptions in this area.
I don't know if you're implicitly only looking for certain types of signed overflow, or if this has been mentioned elsewhere (I admit I had to skim-read some of the thread) but the assumption that signed overflow is defined is _very_ pervasive in gcc at the rtl level. The operand to a CONST_INT is a signed HOST_WIDE_INT, and its accessor macro -- INTVAL -- returns a value of that type. Most arithmetic related to CONST_INTs is therefore done on signed HOST_WIDE_INTs. This means that many parts of gcc would produce wrong code if signed arithmetic saturated, for example. (FWIW, this is why I suggested adding a UINTVAL, which Stuart has since done -- thanks. However, most of gcc still uses INTVAL.) Richard