Trying to understand inconsistent behaviour with -ftrapv (and an ICE)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

This simple program:

#include <stdio.h>
#include <limits.h>
int main(void) {
    volatile int i = INT_MAX + 1u;
    puts("so far so good");
    i = i * -1u;
    puts("never reached with 4.1");
    return 0;
}

when compiled with -ftrapv (using GCC 4.1.1) aborts during the
  i = i * -1u;

Compiling with -ftrapv with older GCC versions (3.3.6, 3.4.6 and 4.0.3)
gets both lines printed. If I understand correctly, both the addition
and the multiplication are done unsigned and so shouldn't cause the
program to abort, and the conversion to int by storing it in i isn't
supposed to cause the program to abort either (and doesn't the first
time), so am I missing something obvious, or might this be a bug?

Something I noticed while writing this mail: probably also interesting
is that if I don't declare i as volatile, and return !i to prevent it
from being optimised away, GCC 4.1.1 ICEs if compiled with -O[23s],
aborts (as with volatile) with -O0, but behaves correctly with -O1. I
can't imagine an ICE not being a bug, but is it the same problem as the
first one, or does it just happen to show up with similar code?

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux