[PATCH v3] LoongArch: fix missing trap for enabled exceptions on narrowing operation
Yury Khrustalev
yury.khrustalev@arm.com
Tue Jul 7 14:06:50 GMT 2026
On Tue, Jul 07, 2026 at 01:46:09PM +0100, Yury Khrustalev wrote:
> On Tue, Mar 24, 2026 at 03:22:59PM +0800, Xi Ruoyao wrote:
> > The libc_feupdateenv_test macro is supposed to trap when the trap for a
> > previously held exception is enabled. But
> > libc_feupdateenv_test_loongarch wasn't doing it properly: the comment
> > claims "setting of the cause bits" would cause "the hardware to generate
> > the exception" but that's simply not true for the LoongArch movgr2fcsr
> > instruction.
> >
> > To fix the issue, we need to call __feraiseexcept in case a held exception
> > is enabled to trap.
> >
> > Reviewed-by: caiyinyu <caiyinyu@loongson.cn>
> > Signed-off-by: Xi Ruoyao <xry111@xry111.site>
> > ---
> >
> > ...
> >
> > diff --git a/math/test-narrowing-trap.c b/math/test-narrowing-trap.c
> > new file mode 100644
> > index 0000000000..a483c4bf1a
> > --- /dev/null
> > +++ b/math/test-narrowing-trap.c
> >
> > ...
> >
> > +static int
> > +do_test (void)
> > +{
> > + pid_t pid;
> > +
> > + if (!EXCEPTION_ENABLE_SUPPORTED (FE_INVALID))
> > + FAIL_UNSUPPORTED ("feenableexcept (FE_INVALID) not supported");
>
> On AArch64 we have
>
> #define EXCEPTION_ENABLE_SUPPORTED(EXCEPT) ((EXCEPT) == 0)
>
> Which means that this test will always be unsupported even if
>
> feenableexcept (FE_INVALID)
>
> would return 0 (compare with math/test-fenv-preserve.c for example).
>
> I think this check is not correct.
>
> Thanks,
> Yury
This simple fix should work I think.
diff --git a/math/test-narrowing-trap.c b/math/test-narrowing-trap.c
index 6d21357913..5871cb33fc 100644
--- a/math/test-narrowing-trap.c
+++ b/math/test-narrowing-trap.c
@@ -29,14 +29,14 @@ do_test (void)
#ifdef FE_INVALID
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 (!EXCEPTION_ENABLE_SUPPORTED (FE_INVALID) && (r == -1))
+ FAIL_UNSUPPORTED ("feenableexcept (FE_INVALID) not supported");
+
TEST_COMPARE (r, 0);
fdiv (0.0, 0.0);
_exit (0);
More information about the Libc-alpha
mailing list