This is the mail archive of the
mailing list for the GCC project.
Re: C as intermediate language, signed integer overflow and -ftrapv
- From: "Thomas Mertes" <thomas dot mertes at gmx dot at>
- To: "Richard Biener" <richard dot guenther at gmail dot com>, gcc at gcc dot gnu dot org
- Date: Fri, 25 Jul 2014 10:43:33 +0200
- Subject: Re: C as intermediate language, signed integer overflow and -ftrapv
- Authentication-results: sourceware.org; auth=none
- References: <trinity-ef56f8a7-8da6-40a9-aea6-658df9967fbc-1406127365897 at 3capp-gmx-bs23> <53D01359 dot 9060708 at LimeGreenSocks dot com>, <CAFiYyc3oEdfEcqQvucp-DHGanCZ4Q+oV++Ggb9cypwyfskE++g at mail dot gmail dot com>
- Sensitivity: Normal
On Thu, Jul 24 at 10:36 PM, Richard Biener <email@example.com> wrote:
> Fact is that if somebody is interested in
> -ftrapv he/she is welcome to contribute patches. Especially testing
> coverage is poor.
As I said I have test programs for integer overflow (not written
in C). Now I have converted one test program to C. This program
checks if an int64_t overflow raises SIGABRT or SIGILL. The name of
the program is chkovf64.c and I have uploaded it to
It is licenced with GPL. You can use it to improve the testing
coverage of gcc. When I compile it with:
gcc -ftrapv chkovf64.c -o chkovf64
it writes a lot of warnings about "integer overflow in expression".
Running chkovf64 shows that -ftrapv does not work correct.
It seems that gcc thinks that writing a warning is enough and
raising a signal at runtime is not necessary. For human
programmers this makes sense, since they read the warnings and
correct the code. But for generated C programs this is not the
right strategy. There are different needs when C is used as
Maybe all -ftrapv problems uncovered by chkovf64.c are because
of this. Unfortunately there are also other test cases where
a signal is not raised although a signed integer overflow occurred.
This happens in a much bigger program and until now I was not
able to create a simple test case from it.
I used clang version 3.4-1 to proof that chkovf64.c works correct.
When I compile it with:
clang -ftrapv chkovf64.c -o chkovf64
and start chkovf64 afterwards it writes:
Overflow checking of negation works correct.
Overflow checking of addition works correct.
Overflow checking of addition assignment works correct.
Overflow checking of subtraction works correct.
Overflow checking of subtraction assignment works correct.
Overflow checking of incr works correct.
Overflow checking of decr works correct.
Overflow checking of multiplication works correct.
Overflow checking of multiplication assignment works correct.
Greetings Thomas Mertes
Seed7 Homepage: http://seed7.sourceforge.net
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.