[Bug c/56956] New: ftrapv traps on valid abs-like code

sunfish at google dot com gcc-bugzilla@gcc.gnu.org
Sun Apr 14 19:14:00 GMT 2013


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

             Bug #: 56956
           Summary: ftrapv traps on valid abs-like code
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sunfish@google.com


This program aborts when compiled with -ftrapv, despite not having any
overflow:

#include <limits.h>
#include <inttypes.h>
#include <stdio.h>

__attribute__((noinline))
uint64_t foo(uint64_t x) {
  return x <= INT64_MAX ? x : -x;
}

int main() {
  uint64_t n = foo((uint64_t)INT64_MIN);
  printf("%" PRIx64 "\n", n);
  return 0;
}

It appears that the code in foo is being folded into an absolute-value
expression which does not work properly on INT64_MIN. However, the code as
written does  handle INT64_MIN without any signed overflow.



More information about the Gcc-bugs mailing list