gcc/libgcc
Jakub Jelinek 2ca373b7e8 libgcc: Fix UB in FP_FROM_BITINT
As I wrote earlier, I was seeing
FAIL: gcc.dg/torture/bitint-24.c   -O0  execution test
FAIL: gcc.dg/torture/bitint-24.c   -O2  execution test
with the ia32 _BitInt enablement patch on i686-linux.  I thought
floatbitintxf.c was miscompiled with -O2 -march=i686 -mtune=generic, but it
turned out to be UB in it.

If a signed _BitInt to be converted to binary floating point has
(after sign extension from possible partial limb to full limb) one or
more most significant limbs equal to all ones and then in the limb below
(the most significant non-~(UBILtype)0 limb) has the most significant limb
cleared, like for 32-bit limbs
0x81582c05U, 0x0a8b01e4U, 0xc1b8b18fU, 0x2aac2a08U, -1U, -1U
then bitint_reduce_prec can't reduce it to that 0x2aac2a08U limb, so
msb is all ones and precision is negative (so it reduced precision from
161 to 192 bits down to 160 bits, in theory could go as low as 129 bits
but that wouldn't change anything on the following behavior).
But still iprec is negative, -160 here.
For that case (i.e. where we are dealing with an negative input), the
code was using 65 - __builtin_clzll (~msb) to compute how many relevant
bits we have from the msb.  Unfortunately that invokes UB for msb all ones.
The right number of relevant bits in that case is 1 though (like for
-2 it is 2 and -4 or -3 3 as already computed) - all we care about from that
is that the most significant bit is set (i.e. the number is negative) and
the bits below that should be supplied from the limbs below.

So, the following patch fixes it by special casing it not to invoke UB.

For msb 0 we already have a special case from before (but that is also
different because msb 0 implies the whole number is 0 given the way
bitint_reduce_prec works - even if we have limbs like ..., 0x80000000U, 0U
the reduction can skip the most significant limb and msb then would be
the one below it), so if iprec > 0, we already don't call __builtin_clzll
on 0.

2024-02-13  Jakub Jelinek  <jakub@redhat.com>

	* soft-fp/bitint.h (FP_FROM_BITINT): If iprec < 0 and msb is all ones,
	just set n to 1 instead of using __builtin_clzll (~msb).
2024-02-13 10:33:08 +01:00
..
c++-minimal Update copyright years. 2024-01-03 12:19:35 +01:00
config x86, libgcc: Implement ia32 basic heap trampoline [PR113855]. 2024-02-12 15:03:12 +00:00
soft-fp libgcc: Fix UB in FP_FROM_BITINT 2024-02-13 10:33:08 +01:00
ChangeLog Daily bump. 2024-02-13 00:17:51 +00:00
config.host x86, libgcc: Implement ia32 basic heap trampoline [PR113855]. 2024-02-12 15:03:12 +00:00
config.in libgcc: Fix config.in 2023-12-08 12:35:40 +00:00
configure libgcc: aarch64: Configure check for __getauxval 2023-12-08 11:29:06 +00:00
configure.ac libgcc: aarch64: Configure check for __getauxval 2023-12-08 11:29:06 +00:00
crtstuff.c Update copyright years. 2024-01-03 12:19:35 +01:00
dfp-bit.c Update copyright years. 2024-01-03 12:19:35 +01:00
dfp-bit.h Update copyright years. 2024-01-03 12:19:35 +01:00
divmod.c Update copyright years. 2024-01-03 12:19:35 +01:00
emutls.c Update copyright years. 2024-01-03 12:19:35 +01:00
enable-execute-stack-empty.c
enable-execute-stack-mprotect.c Update copyright years. 2024-01-03 12:19:35 +01:00
find-symver.awk Update copyright years. 2024-01-03 12:19:35 +01:00
fixed-bit.c Update copyright years. 2024-01-03 12:19:35 +01:00
fixed-bit.h Update copyright years. 2024-01-03 12:19:35 +01:00
fixed-obj.mk
floatunsidf.c
floatunsisf.c
floatunsitf.c
floatunsixf.c
fp-bit.c Update copyright years. 2024-01-03 12:19:35 +01:00
fp-bit.h Update copyright years. 2024-01-03 12:19:35 +01:00
gbl-ctors.h Update copyright years. 2024-01-03 12:19:35 +01:00
gcov.h Update copyright years. 2024-01-03 12:19:35 +01:00
gen-fixed.sh
generic-morestack-thread.c Update copyright years. 2024-01-03 12:19:35 +01:00
generic-morestack.c Update copyright years. 2024-01-03 12:19:35 +01:00
generic-morestack.h Update copyright years. 2024-01-03 12:19:35 +01:00
gstdint.h
gthr-posix.h Update copyright years. 2024-01-03 12:19:35 +01:00
gthr-single.h Update copyright years. 2024-01-03 12:19:35 +01:00
gthr.h Update copyright years. 2024-01-03 12:19:35 +01:00
hardcfr.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgcc2.c libgcc: Fix up _BitInt division [PR113604] 2024-02-02 22:14:33 +01:00
libgcc2.h libgcc: Avoid warnings on __gcc_nested_func_ptr_created [PR113402] 2024-02-01 21:10:10 +01:00
libgcc-std.ver.in Fix __builtin_nested_func_ptr_{created,deleted} symbol versions [PR113402] 2024-01-28 10:59:34 +00:00
libgcov-driver-system.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgcov-driver.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgcov-interface.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgcov-merge.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgcov-profiler.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgcov-util.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgcov.h Update copyright years. 2024-01-03 12:19:35 +01:00
Makefile.in Update copyright years. 2024-01-03 12:19:35 +01:00
memcmp.c
memcpy.c
memmove.c
memset.c
mkheader.sh Update copyright years. 2024-01-03 12:19:35 +01:00
mkmap-flat.awk Update copyright years. 2024-01-03 12:19:35 +01:00
mkmap-symver.awk Update copyright years. 2024-01-03 12:19:35 +01:00
offloadstuff.c Update copyright years. 2024-01-03 12:19:35 +01:00
shared-object.mk
siditi-object.mk
static-object.mk
strub.c Update copyright years. 2024-01-03 12:19:35 +01:00
sync.c Update copyright years. 2024-01-03 12:19:35 +01:00
udivhi3.c Update copyright years. 2024-01-03 12:19:35 +01:00
udivmod.c Update copyright years. 2024-01-03 12:19:35 +01:00
udivmodhi4.c Update copyright years. 2024-01-03 12:19:35 +01:00
udivmodsi4.c Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-arm-common.inc Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-c.c Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-compat.c Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-compat.h Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-dw2-btree.h Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-dw2-execute_cfa.h Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-dw2-fde-compat.c Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-dw2-fde-dip.c libgcc, nios2: Fix exception handling on nios2 with -fpic 2024-01-12 04:50:22 +00:00
unwind-dw2-fde.c Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-dw2-fde.h Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-dw2.c Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-dw2.h Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-generic.h Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-pe.h Update copyright years. 2024-01-03 12:19:35 +01:00
unwind-seh.c libgcc: fix SEH C++ rethrow semantics [PR113337] 2024-02-06 08:23:26 +00:00
unwind-sjlj.c Update copyright years. 2024-01-03 12:19:35 +01:00
unwind.inc Update copyright years. 2024-01-03 12:19:35 +01:00
vtv_end_preinit.c Update copyright years. 2024-01-03 12:19:35 +01:00
vtv_end.c Update copyright years. 2024-01-03 12:19:35 +01:00
vtv_start_preinit.c Update copyright years. 2024-01-03 12:19:35 +01:00
vtv_start.c Update copyright years. 2024-01-03 12:19:35 +01:00