This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/68046] -ftrapv doesn't catch leaq-based overflows on x86-64
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 22 Oct 2015 08:47:09 +0000
- Subject: [Bug middle-end/68046] -ftrapv doesn't catch leaq-based overflows on x86-64
- Auto-submitted: auto-generated
- References: <bug-68046-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68046
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note that -fsanitize-undefined doesn't properly handle
volatile int x = __INT_MAX__ + 1;
which is in PR61893, it handles the case in this PR fine and with
trap-on-error more efficiently than -ftrapv:
main:
.LFB0:
.cfi_startproc
movq i(%rip), %rax
movq %rax, %rdx
addq $1, %rdx
jo .L6
cmpq %rdx, %rax
setg %al
movzbl %al, %eax
ret
.L6:
ud2
.cfi_endproc
of course you simply get a SIGILL (on x86_64), an option to use
abort () would be more "compatible" with how -ftrapv behaves
(abort is also used on targets that do not have a trapping instruction
defined).