Message ID | 20250425205618.360232-8-adhemerval.zanella@linaro.org |
---|---|
State | Accepted |
Commit | 7a0d7fb25c22cc7237315792b0f340ec49e3783f |
Headers | show |
Series | Fix UB in math implementations | expand |
On 4/25/25 4:54 PM, Adhemerval Zanella wrote: > The left shift overflows for 'int', use uint64_t instead. It syncs > with CORE-MATH commit d0a2be200cbc1344d800d9ef0ebee9ad67dd3ad8. > > Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. LGTM. Reviewed-by: Carlos O'Donell <carlos@redhat.com> > --- > sysdeps/ieee754/flt-32/s_erfcf.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/sysdeps/ieee754/flt-32/s_erfcf.c b/sysdeps/ieee754/flt-32/s_erfcf.c > index 3dae2a0b0e..955f129148 100644 > --- a/sysdeps/ieee754/flt-32/s_erfcf.c > +++ b/sysdeps/ieee754/flt-32/s_erfcf.c > @@ -3,7 +3,7 @@ > Copyright (c) 2023, 2024 Alexei Sibidanov. > > This file is part of the CORE-MATH project > -project (file src/binary32/erfc/erfcf.c revision bc385c2). > +project (file src/binary32/erfc/erfcf.c revision d0a2be20). OK. > > Permission is hereby granted, free of charge, to any person obtaining a copy > of this software and associated documentation files (the "Software"), to deal > @@ -142,7 +142,7 @@ __erfcf (float xf) > const double ln2l = 0x1.cf79abd6f5dc8p-47; > uint64_t jt = asuint64 (fma (x2, iln2, -(1024 + 0x1p-8))); > int64_t j = (int64_t) (jt << 12) >> 48; > - double S = asdouble (((j >> 7) + (0x3ff | sgn << 11)) << 52); > + double S = asdouble ((uint64_t)((j >> 7) + (0x3ff | sgn << 11)) << 52); > static const double ch[] = > { > -0x1.ffffffffff333p-2, 0x1.5555555556a14p-3, -0x1.55556666659b4p-5, OK. commit d0a2be200cbc1344d800d9ef0ebee9ad67dd3ad8 Author: Paul Zimmermann <Paul.Zimmermann@inria.fr> Date: Mon Mar 17 12:38:44 2025 +0100 [erfcf] fixed undefined behavior
diff --git a/sysdeps/ieee754/flt-32/s_erfcf.c b/sysdeps/ieee754/flt-32/s_erfcf.c index 3dae2a0b0e..955f129148 100644 --- a/sysdeps/ieee754/flt-32/s_erfcf.c +++ b/sysdeps/ieee754/flt-32/s_erfcf.c @@ -3,7 +3,7 @@ Copyright (c) 2023, 2024 Alexei Sibidanov. This file is part of the CORE-MATH project -project (file src/binary32/erfc/erfcf.c revision bc385c2). +project (file src/binary32/erfc/erfcf.c revision d0a2be20). Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -142,7 +142,7 @@ __erfcf (float xf) const double ln2l = 0x1.cf79abd6f5dc8p-47; uint64_t jt = asuint64 (fma (x2, iln2, -(1024 + 0x1p-8))); int64_t j = (int64_t) (jt << 12) >> 48; - double S = asdouble (((j >> 7) + (0x3ff | sgn << 11)) << 52); + double S = asdouble ((uint64_t)((j >> 7) + (0x3ff | sgn << 11)) << 52); static const double ch[] = { -0x1.ffffffffff333p-2, 0x1.5555555556a14p-3, -0x1.55556666659b4p-5,