[Issue 20743] Checked!(int, Abort) does not abort but raise SIGFPE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 21 19:49:41 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20743

wolframw <wolframw at protonmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wolframw at protonmail.com

--- Comment #1 from wolframw <wolframw at protonmail.com> ---
This is caused by Warn.onOverflow (which is called by Abort.onOverflow)
returning the result of a / b. In case of an overflow, the IDIV instruction
triggers a division error which then causes SIGFPE.

On Windows, something similar happens. Although there are no POSIX signals, an
EXCEPTION_INT_OVERFLOW (code 0xC0000095) is thrown (via "Structured Exception
Handling"). This exception is seemingly caught by D runtime translated into a
Throwable that is printed as "Integer Overflow" (so NOT an assertion fault).

Note that this only happens for division. Overflows caused by multiplication
do not behave like this (even though, mathematically speaking, a / -1 = a *
-1).

In my opinion, the best way to deal with this would be to specifically check if
the offending calculation was a division, in which case int.min would be
returned (otherwise, keep it as-is, i.e. use the mixin to get a result).

Any other suggestions?

--


More information about the Digitalmars-d-bugs mailing list