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 target/35646] New: gcc is not using the overflow flag


Two simple examples:

unsigned int add(unsigned int a,unsigned int b) {
  if (a+b<a) exit(0);
  return a+b;
}

This produces code without an extra cmp, as expected.

void addto(unsigned int* a,unsigned int b) {
  if ((*a+=b)<b) exit(0);
}

This generates this code:

        movl    %esi, %eax
        addl    (%rdi), %eax
        cmpl    %eax, %esi
        movl    %eax, (%rdi)
        ja      .L5

I would have expected something like:

        addl    %esi, (%rdi)
        jo      .L5

Can we please fix this?  It is a common case for integer overflow checking, and
if we could get programmers to see that checking for integer overflows is not
inefficient and you don't need some inline assembly code to get it to be
efficient, that would help a lot.


-- 
           Summary: gcc is not using the overflow flag
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: felix-gcc at fefe dot de
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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