This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Ada front-end depends on signed overflow
- From: Paul Schlie <schlie at comcast dot net>
- To: Joe Buck <Joe dot Buck at synopsys dot COM>,Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: Florian Weimer <fw at deneb dot enyo dot de>,GCC List <gcc at gcc dot gnu dot org>,<bosch at gnat dot com>
- Date: Fri, 03 Jun 2005 13:03:40 -0400
- Subject: Re: Ada front-end depends on signed overflow
> From: Joe Buck <Joe.Buck@synopsys.COM>
>> On Fri, Jun 03, 2005 at 11:43:32AM -0400, Andrew Pinski wrote:
>> Everyone's who writes C/C++ should know that overflow of signed is undefined.
>
> In practice, however, this issue is commonly ignored, because people code
> in a hurry, then test the behavior of the executable code, and if on all
> platforms tested there are overflows, but the overflows wrap and as a
> result the expected thing happens, the problem will not be noticed.
>
> I'm sure there are plenty of production codes that assume signed integer
> overflow wraps, or at least make the weaker assumption that in
>
> a = b + c + d;
>
> where all variables are integers, if one of the intermediate terms
> can't be represented in an integer, we still get the correct result
> if the final result is representable in an integer.
Agreed:
- which why it should be assumed to wrap, especially given that most/all
current target, and likely most/all future targets do wrap (not trap)
signed overflows. (so would expect the compiler to ideally reflect reality
when analyzing code for optimization, not assume that "undefined" means
"ignore reality")?