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: Type conversion and addition


On Fri, 24 Mar 2006, Eric Botcazou wrote:

> After the change it is simplified to (int)((unsigned int)j + (unsigned int)o).
> Now take j=0 and o=-1.  There is signed-overflow undefinedness neither in the 
> original expression nor in the original simplified expression while there is 
> in the new simplified expression when UINT_MAX is cast to int.

Conversion of unsigned to int does not involve undefined behavior, it 
involves implementation-defined behavior, which GCC defines in 
implement-c.texi:

    @item
    @cite{The result of, or the signal raised by, converting an integer to a
    signed integer type when the value cannot be represented in an object of
    that type (C90 6.2.1.2, C99 6.3.1.3).}

    For conversion to a type of width @math{N}, the value is reduced
    modulo @math{2^N} to be within range of the type; no signal is raised.

This is of course a definition of C semantics rather than tree semantics, 
but I believe our trees follow the C semantics here.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


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