This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Division by zero
- From: "Jie Zhang" <jzhang918 at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 10 Feb 2007 12:59:55 +0800
- Subject: Division by zero
Hi,
Division by zero is undefined. We chose to keep it:
http://gcc.gnu.org/ml/gcc-patches/2001-06/msg01068.html
But now gcc seems to optimize it away. For the following function:
$ cat t.c
#include <limits.h>
void foo (int rc)
{
int x = rc / INT_MAX;
x = 4 / x;
}
$ gcc -O2 -S t.c
$ cat t.s
.file "t.c"
.text
.p2align 4,,15
.globl foo
.type foo, @function
foo:
pushl %ebp
movl %esp, %ebp
popl %ebp
ret
.size foo, .-foo
.ident "GCC: (GNU) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)"
.section .note.GNU-stack,"",@progbits
Does we now choose to optimize it away now?
Jie