This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: how to make gcc warn about arithmetic signed overflow
- From: Andrew Haley <aph at redhat dot com>
- To: Dave Allured - NOAA Affiliate <dave dot allured at noaa dot gov>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 23 Sep 2013 20:48:23 +0100
- Subject: Re: how to make gcc warn about arithmetic signed overflow
- Authentication-results: sourceware.org; auth=none
- References: <20130921164609 dot GC3086 at a dot lan> <CAH6eHdTToM+TMy55m5HYo39DC8nA0RrTma1Bp5OnhUtPErMfOA at mail dot gmail dot com> <20130921174229 dot GD3086 at a dot lan> <CAH6eHdQzJNQY4Meysi259RheSaGscKUF28OW43OvOD1rf6FkxQ at mail dot gmail dot com> <20130923000355 dot fa2a964c dot jklowden at schemamania dot org> <CALqwTFMfRi6sZY6Ffpdp0E4d4xiJT0EHRUQH-+Oph5c5AWR3-Q at mail dot gmail dot com>
On 09/23/2013 08:38 PM, Dave Allured - NOAA Affiliate wrote:
> I believe the CPU overflow flag is updated after most integer
> arithmetic instructions. Does GCC have any facility for checking this
> flag after each integer operation? This would be a runtime check, of
> course, not a compile time check.
It wouldn't help with optimized code. GCC reorganizes code, and it
assumes that overflow doesn't happen. GCC inserts some arithmetic
instructions while optimizing and deletes others. So, even if an
overflow happens in your code, it doesn't necessarily happen at
runtime.
Andrew.