Issue 5908 - Optimizer generates wrong value with divide-by-zero.#3810
Issue 5908 - Optimizer generates wrong value with divide-by-zero.#3810WalterBright merged 1 commit intodlang:masterfrom
Conversation
|
Huh – shouldn't this produce a runtime FP exception? |
|
It does if it can't catch it at compile time. |
src/backend/evalu8.c
Outdated
There was a problem hiding this comment.
Not necessary since OPremquo is only for integral operands. You can document this by inserting assert(!tyfloating(tym)) instead.
There was a problem hiding this comment.
That makes sense. Updated.
|
Integer divide by zero should not raise a FP exception. There are also issues with the following code: The optimizer will, because of constant propagation, see |
I'm not so sure about that example. b is a constant, so I think the division by zero is always a bug, whether it's guarded by an if or not. We have the same issue with null dereference. It can easily be worked around by adding |
Reinstate optimizer error for integer division by zero
That's right, we do have the same issue with null dereference being detected by the optimizer using data flow analysis, and I had to disable the error message because real code would trip the error even though the code logic ensured it would never happen. Here's another example: The optimizer sees a path where b could be 0, and would issue the error. But that path would never happen. |
This error doesn't appear when b could be 0, only when it must be zero. My understanding is it's conservative. |
|
@WalterBright: Feedback on the previous comment? |
|
Auto-merge toggled on |
|
Thought we'd give it a try and see what happens. |
|
Fingers crossed! |
Issue 5908 - Optimizer generates wrong value with divide-by-zero.
Reinstate optimizer error for integer division by zero
https://issues.dlang.org/show_bug.cgi?id=5908