PATCH: Bad signed int to long long conversion

Vincent Lefevre vincent at
Thu Dec 1 14:12:41 CET 2011

On 2011-12-01 13:13:05 +0100, Torbjorn Granlund wrote:
> Let's not get too alarmed by this "bug";
> I'd argue that the real bug is in the C standard.

No, the C standard is correct.

> No compiler will let signed negation be anything but that same operation
> in the same-width unsigned type.

That would be a bad behavior. If x < 0, then one expects -x to be
positive. So, the compiler should be allowed to (depending on the
  * do optimizations based on this fact (VRP doesn't work well
    without this rule);
  * signal a bug in the program by allowing runtime exceptions when
    such operations occur.

> The GCC bug report involves two operand sizes, and is indeed invalid.

AFAIK, the VRP logic is not based on these two operand sizes.
What matters here is that the subtraction (where only one type
is involved) overflows and GCC assumes that this cannot occur
in a correct program.

Vincent Lefèvre <vincent at> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)

More information about the gmp-bugs mailing list