This is the mail archive of the 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 

    @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, C99}

    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      (personal mail) (CodeSourcery mail) (Bugzilla assignments and CCs)

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