[PATCH v2] LoongArch: fix missing trap for enabled exceptions on narrowing operation
Florian Weimer
fweimer@redhat.com
Fri Mar 20 10:50:30 GMT 2026
* Xi Ruoyao:
> diff --git a/math/test-narrowing-trap.c b/math/test-narrowing-trap.c
> new file mode 100644
> index 0000000000..27c31245c1
> --- /dev/null
> +++ b/math/test-narrowing-trap.c
> @@ -0,0 +1,60 @@
> +/* Copyright (C) 2026 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +#ifndef _GNU_SOURCE
> +# define _GNU_SOURCE
> +#endif
We automatically define _GNU_SOURCE for tests, so that's unnecessary.
> +#include <fenv.h>
> +#include <math.h>
> +#include <math-tests.h>
> +#include <signal.h>
> +#include <stdlib.h>
> +#include <support/check.h>
> +#include <support/xunistd.h>
> +
> +static int
> +do_test (void)
> +{
> + pid_t pid;
> +
> + if (!EXCEPTION_ENABLE_SUPPORTED (FE_INVALID))
> + FAIL_UNSUPPORTED ("feenableexcept (FE_INVALID) not supported");
> +
> + pid = xfork ();
> + if (pid == 0)
> + {
> + int r = feenableexcept (FE_INVALID);
> + if (r == -1)
> + exit (2);
Tabs vs spaces inconsistency, I think. And you could use
TEST_VERIFY (r != -1). The test framework uses a shared memory
segment, so that subtest failures after fork are communicated
outwards even if the exit status is zero.
> + fdiv (0.0, 0.0);
> + exit (0);
This should be _exit (0), so that atexit handlers are not run twice.
(We have protection against this internally, but I think test
code should show how to use fork correctly if possible.)
Sorry, should have mentioned that before.
Thanks,
Florian
More information about the Libc-alpha
mailing list