[cfe-commits] r126816 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/integer-overflow.c

Eli Friedman eli.friedman at gmail.com
Wed Mar 2 13:00:58 PST 2011


On Wed, Mar 2, 2011 at 1:32 AM, Frits van Bommel <fvbommel at gmail.com> wrote:
> On Wed, Mar 2, 2011 at 2:49 AM, Eli Friedman <eli.friedman at gmail.com> wrote:
>> PR9350: increment/decrement of char (and anything else narrower than int)
>> can't overflow due to promotion rules; emit a wrapping add for those cases.
>
> The addition may not be able to overflow, but if the result is not
> representable in the (signed) character type it's converted to then
> "either the result is implementation-defined or an
> implementation-defined signal is raised" [C99 6.3.1.3p3].
> However, I'm not fluent enough in standardese to know whether that
> allows a non-wrapping add to be used in this case. Is 'undef' a valid
> implementation-defined result?
> (Also, I didn't check C89 or any C++ standards)

Our "implementation-defined" behavior for a narrowing cast is "do 2's
complement truncation".  In theory, we could define our behavior to be
something else, but that would be inconsistent with practically every
other C implementation in existence.

-Eli



More information about the cfe-commits mailing list