Bug 36868 - -ftrapv doesn't trap
Summary: -ftrapv doesn't trap
Status: RESOLVED DUPLICATE of bug 19020
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2008-07-18 18:20 UTC by Mike Stump
Modified: 2008-07-18 18:22 UTC (History)
11 users (show)

See Also:
Host: i686-apple-darwin9
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Mike Stump 2008-07-18 18:20:23 UTC
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() {
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
Comment 1 Richard Biener 2008-07-18 18:22:31 UTC

*** This bug has been marked as a duplicate of 19020 ***