[LLVMdev] Integer divide by zero

Cameron McInally cameron.mcinally at nyu.edu
Fri Apr 5 20:02:30 PDT 2013


On Fri, Apr 5, 2013 at 6:49 PM, Joe Groff <arcata at gmail.com> wrote:
...

The platform is irrelevant; division by zero is undefined, and compilers
> are allowed to optimize as if it can't happen.
>

Understood.

I don't mean to nag, but I'm not arguing which is [more] correct: the
Standards or the platform. Both have their own merits. At least to me they
both have merits. The choice should be up to the compiler implementor. And,
I would like to see LLVM make that choice easy for the compiler
implementor. Maybe an anachronism, but there is some history of this option
being built-in to other major compilers: GNU, Sun, HP, IBM, SGI, Compaq,
etc.

But, if others can not (or will not) benefit from this option, I will not
force my individual needs on the whole.

Both gcc and clang will lift the division out of this loop, for example,
> causing the hardware trap to happen in the "wrong" place if bar is passed
> zero:
>
> void foo(int x, int y);
>
> void bar(int x) {
> for (int i = 0; i < 100; ++i) {
> foo(i, 200/x);
> }
> }
>

I'm less concerned about "where" the trap happens as I am about "if" it
happens. For example, a Fortran program with division-by-zero is, by the
Standard, non-conforming. Pragmatically, not a Fortran program. Rather than
wrong answers, I would like to see a hard error indicating that a program
is non-conforming to the Standard.
-Cameron

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130405/62181469/attachment.html>


More information about the llvm-dev mailing list