[LLVMdev] Integer divide by zero

Owen Anderson resistor at mac.com
Fri Apr 5 22:18:48 PDT 2013


On Apr 5, 2013, at 8:02 PM, Cameron McInally <cameron.mcinally at nyu.edu> wrote:

> 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.

As I've pointed out, clang does provide such functionality as an opt-in feature through its -fsanitize options.  A hypothetical Fortran frontend could do the same, and even make it an opt-out feature if it chose.  I'm sorry if its implementation mechanism doesn't match exactly what you want it to be, but it's not like nobody else has thought about this problem.  They have, and they've designed and shipped a solution!

Side note: even if the -fsanitize option introduces a branch around the division (which I haven't verified), it's quite unlikely to cause a significant performance regression.  The branch to the error block should be perfectly predicted on any CPU made in the last 25 years.

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


More information about the llvm-dev mailing list