oops, forgot the "Fixes" line. Sent a v2.

--
Nadav Har'El
n...@scylladb.com


On Wed, Jan 11, 2023 at 1:53 PM Nadav Har'El <n...@scylladb.com> wrote:

> tst-feexcept.cc checks several aspects of SIGFPE. One of the things
> we noticed in the past, and tested, is that division by *integer* zero
> also generates SIGFPE. We had a test for this using C code, but
> unfortunately C and C++ chose to make division by zero "undefined",
> and starting with Gcc 12, 1/0 started to return 0 instead of SIGFPE
> which broke this test.
>
> Changed the test to do division by zero in assembly-language, which
> still causes a SIGFPE.
>
> Signed-off-by: Nadav Har'El <n...@scylladb.com>
> ---
>  tests/tst-feexcept.cc | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tests/tst-feexcept.cc b/tests/tst-feexcept.cc
> index 5d5ddc1f..403185b6 100644
> --- a/tests/tst-feexcept.cc
> +++ b/tests/tst-feexcept.cc
> @@ -78,8 +78,12 @@ int main(int argc, char **argv)
>      // Test that fegetexcept() does not return a negative number
>      expect(fegetexcept() >= 0, true);
>
> -    // Test that *integer* division by zero generates, ironically, a
> SIGFPE
> -    expect(sig_check([] { printf("%d\n", 1 / zero_i()); }, SIGFPE), true);
> +    // Test that *integer* division by zero generates, ironically, a
> SIGFPE.
> +    // Starting with Gcc 12, division by zero in C no longer generates a
> +    // SIGFPE and just returns 0. So to check this we need to use assembly
> +    // directly.
> +    //expect(sig_check([] { printf("%d\n", 1 / zero_i()); }, SIGFPE),
> true);
> +    expect(sig_check([] { asm("movl $1,%eax; movl $0,%ebx; movl $0, %edx;
> divl %ebx;"); }, SIGFPE), true);
>
>      // While, continuing the irony, by default a floating-point division
> by
>      // zero does NOT generate a SIGFPE signal, but rather inf or nan:
> --
> 2.39.0
>
>

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/CANEVyju3Yj16rQqVSoEc7aKa41_PkMEgOh_fEADpBoCrdFX30g%40mail.gmail.com.

Reply via email to