User account creation filtered due to spam.

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
URL:
Keywords:
Depends on:
Blocks:
 
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
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

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() {
    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
Comment 1 Richard Biener 2008-07-18 18:22:31 UTC

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