This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/57859] New: -ftrapv does not trap on signed overflows for struct fields (32-bit mode)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57859

            Bug ID: 57859
           Summary: -ftrapv does not trap on signed overflows for struct
                    fields (32-bit mode)
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu

The following code (which has a signed integer overflow) doesn't trap when
compiled at -O1 or above with -ftrapv on x86_64-linux. This applies to the
current gcc trunk, as well as gcc-4.6, gcc-4.7, and gcc-4.8. 

$ gcc-trunk -v
gcc version 4.9.0 20130708 (experimental) [trunk revision 200751] (GCC) 
$ gcc-trunk -m32 -O0 -ftrapv small.c
$ a.out
Aborted (core dumped)
$ gcc-trunk -m32 -O1 -ftrapv small.c      
$ a.out
$ gcc-4.8 -m32 -O1 -ftrapv small.c
$ a.out
$ gcc-4.7 -m32 -O1 -ftrapv small.c
$ a.out
$ gcc-4.6 -m32 -O1 -ftrapv small.c
$ a.out
$ 


-------------------------------------------


struct S
{
  int f;
}; 

int
main ()
{
  struct S s; 
  for (s.f = 1; s.f > 0; ++s.f)
    ; 
  return 0;
}


-------------------------------------------

The following code does trap in 32-bit mode (but still not in 64-bit): 

int
main ()
{
  int i; 
  for (i = 1; i > 0; ++i)
    ; 
  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]