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: unassig...@gcc.gnu.org ReportedBy: sunf...@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.