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: Sun, 27 Jul 2014 09:13:22 +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> <trinity-cd88fe45-1800-4151-8a0b-cf48a7b97d33-1406277813651 at 3capp-gmx-bs47>, <CAFiYyc0A3qqz7zqN6Fym177YC29pm-9gEmPes4LR-XerEMfo=A at mail dot gmail dot com>
- Sensitivity: Normal
On Fri, Jul 25, 2014 at 12:35, Richard Biener <email@example.com> wrote:
> On Fri, Jul 25, 2014 at 10:43 AM, Thomas Mertes <firstname.lastname@example.org> wrote:
> > 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
> > http://sourceforge.net/projects/seed7/files/
> > 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.
> That's https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61893 - basically
> as soon as we can constant-fold we lose the trap. Which is probably
> not important for practical purposes, but you have a point here.
For human programmers it is probably ok to have a warning instead of
the trap. But when the C program has been generated (C as intermediate
language) it is important that the trap is not lost.
Isn't possible that constant-fold has the result "it will overflow"?
Hopefully it is not necessary to omit an optimization because of -ftrapv.
For my use-case that would be bad. I need -ftrapv together with all
optimizations for production code and NOT for debugging purposes.
> > 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.
> Yes, not all optimizations may be aware of -ftrapv.
In the case above (the much bigger program) the error (overflow without
raising SIGABRT) happens when I compile without -O and without -g.
When I use -g the signal SIGABRT is raised. I still don't have a simple
test case, sorry.
Did you have a look at chkovf64.c?
Is it useable as test program for -ftrapv?
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.