http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54846
Bug #: 54846
Summary: -ftrapv doesn't work in 64-bit mode
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: [email protected]
ReportedBy: [email protected]
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
-ftrapv flag should generate a crash if integer overflow happens. But it
doesn't
work in 64-bit mode.
Try this:
#include <stdio.h>
int main(void)
{
int a = 0x70000000;
int b = 0x50000000;
int c = a + b;
printf("%x\n", c);
return 0;
}
When compiled with "-ftrapv -m32", an abort happens. However, when compiled
with "-ftrapv -m64", there is no crash. If we look at assembler output, we see
that it uses function __addvdi3 to do the addition. This function is for 64-bit
numbers, not for 32-bit. If I replace __addvdi3 with __addvsi3, an abort
happens correctly.