how to make gcc warn about arithmetic signed overflow

Vincent Lefevre vincent+gcc@vinc17.org
Fri Sep 27 07:58:00 GMT 2013


On 2013-09-26 18:30:10 +0100, Andrew Haley wrote:
> On 09/26/2013 06:02 PM, Vincent Lefevre wrote:
> > On 2013-09-26 15:49:05 +0100, Andrew Haley wrote:
> >> On 09/26/2013 09:29 AM, Vincent Lefevre wrote:
> >>> On 2013-09-25 22:29:58 -0400, James K. Lowden wrote:
> >>>> You mean that a naïve rendering of the source code implies an overflow
> >>>> where none might exist in the actual emitted object code.  And,
> >>>> presumably, the converse: that even if the source is written such that
> >>>> there logically can't be an overflow, the compiler might render object
> >>>> code that does.
> >>>
> >>> The converse is forbidden.
> >>
> >> You'll find it hard to justify that by any language in the standard.
> > 
> > What do you mean?
> 
> There is no reason why a compiler should not generate an overflow
> where none is written in the program, as long as it doesn't generate
> a different result.

OK, I wouldn't call that an overflow, then. I thought you meant
rewrite the code in an intermediate step, generating an overflow,
before knowing the consequences at the target level. The term
"overflow" has a connotation of exception / undefined behavior.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



More information about the Gcc-help mailing list