This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/36868] New: -ftrapv doesn't trap
- From: "mrs at apple dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Jul 2008 18:20:24 -0000
- Subject: [Bug c/36868] New: -ftrapv doesn't trap
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The -ftrapv doesn't seem to want to generate code that will trap on overflow
with optimization. I've tried with and without -fwrapv to try and get it to
work.
$ cat t.c
#include <stdio.h>
int foo( int a) {
if (a + 100 < a) {
printf("Integer overflow detected!\n");
} else {
printf("Integer overflow not detected!\n");
}
return a;
}
int main() {
foo(0x7fffffff);
}
mrs2 $ ./xgcc -B./ -fno-wrapv -ftrapv t.c -O2
mrs2 $ a.out
Integer overflow detected!
mrs2 $ ./xgcc -B./ -fwrapv -ftrapv t.c -O2
mrs2 $ a.out
Integer overflow detected!
mrs2 $ ./xgcc -B./ -fwrapv -ftrapv t.c
mrs2 $ a.out
Abort trap
mrs2 $ ./xgcc -B./ -fno-wrapv -ftrapv t.c
mrs2 $ a.out
Abort trap
--
Summary: -ftrapv doesn't trap
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mrs at apple dot com
GCC host triplet: i686-apple-darwin9
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36868