[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GCC optimizes integer overflow: bug or feature?
From: |
Joseph S. Myers |
Subject: |
Re: GCC optimizes integer overflow: bug or feature? |
Date: |
Thu, 21 Dec 2006 20:26:28 +0000 (UTC) |
On Thu, 21 Dec 2006, Paul Eggert wrote:
> But because bigtime_test wants an int, this causes the test
> program to compute the equivalent of (int) ((unsigned int)
> INT_MAX + 1), and C99 says that if you cannot assume
> wrapping semantics this expression has undefined behavior in
> the common case where INT_MAX < UINT_MAX.
Conversion of out-of-range integers to signed types is
implementation-defined not undefined, and GCC duly documents the modulo
semantics for that conversion. I don't know if you have to deal with
compilers applying different semantics there, but shared overflow checking
functions in gnulib could deal with the differences between compilers.
(Conversion of out-of-range floating-point numbers to integer types *is*
undefined, but Annex F changes this to returning an unspecified value so
bounding the possible behavior, and I believe GCC follows Annex F for
this: it's useful not to have to guarantee any particular result, since
different machines have conversion instructions that may do different
things for out-of-range values, and to be able to return different results
for compile-time and run-time conversions, but floating-point conversions
don't have the same scope as integer arithmetic for useful optimization
based on undefined behavior.)
--
Joseph S. Myers
address@hidden
- Re: GCC optimizes integer overflow: bug or feature?, (continued)
- Re: GCC optimizes integer overflow: bug or feature?, Robert Dewar, 2006/12/22
- Re: GCC optimizes integer overflow: bug or feature?, Rask Ingemann Lambertsen, 2006/12/23
- Re: GCC optimizes integer overflow: bug or feature?, Denis Vlasenko, 2006/12/23
- Re: GCC optimizes integer overflow: bug or feature?, Rask Ingemann Lambertsen, 2006/12/23
- Re: GCC optimizes integer overflow: bug or feature?, Gabriel Dos Reis, 2006/12/20
- Re: GCC optimizes integer overflow: bug or feature?, Robert Dewar, 2006/12/20
- Message not available
- Re: GCC optimizes integer overflow: bug or feature?, Paolo Bonzini, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Paul Eggert, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?,
Joseph S. Myers <=
- Re: GCC optimizes integer overflow: bug or feature?, Paul Eggert, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Ian Lance Taylor, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Joseph S. Myers, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Paul Eggert, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Gabriel Dos Reis, 2006/12/21
- Re: GCC optimizes integer overflow: bug or feature?, Paolo Bonzini, 2006/12/22
- Re: GCC optimizes integer overflow: bug or feature?, Paolo Bonzini, 2006/12/22
- Re: GCC optimizes integer overflow: bug or feature?, Paul Eggert, 2006/12/29
- Message not available
- Re: GCC optimizes integer overflow: bug or feature?, Toon Moene, 2006/12/27
- Re: GCC optimizes integer overflow: bug or feature?, Joe Buck, 2006/12/20