Philipp Tomsich a66820ce3f tree-optimization/122569 - fix DeBruijn CLZ table validator shift-by-64 UB
simplify_count_zeroes validates DeBruijn CLZ tables by computing
(1 << (data + 1)) - 1 to simulate the value produced by the OR-cascade
b |= b >> 1; ... b |= b >> 32.  For 64-bit input with data == 63 (the
MSB bit), data + 1 equals HOST_BITS_PER_WIDE_INT, making the shift
(HOST_WIDE_INT_1U << 64) undefined behavior.  Hosts typically produce
0, so the check (0 * magic) >> 58 == 63 fails and check_table_array
returns false.

Every well-formed 64-bit DeBruijn CLZ table has an entry mapping the
all-ones value to bit 63, so this UB rejected every such table --
including the magic 0x03f79d71b4cb0a89 used in Stockfish's msb(),
zstd's bits.h, and cpython's pycore_bitutils.h.

Fix by special-casing data + 1 == HOST_BITS_PER_WIDE_INT to use
HOST_WIDE_INT_M1U.  Only the 64-bit CLZ path is affected.

gcc/ChangeLog:

	PR tree-optimization/122569
	* tree-ssa-forwprop.cc (simplify_count_zeroes): Avoid
	shift-by-HOST_BITS_PER_WIDE_INT UB when computing the all-ones
	value for the CLZ validator.

gcc/testsuite/ChangeLog:

	PR tree-optimization/122569
	* gcc.dg/tree-ssa/pr122569-1.c: New test.
	* gcc.dg/tree-ssa/pr122569-2.c: New test.
2026-05-03 22:00:51 +02:00
2026-05-01 00:16:27 +00:00
2026-04-24 00:16:27 +00:00
2026-04-29 00:16:40 +00:00
2026-04-30 00:16:31 +00:00
2026-05-03 00:16:23 +00:00
2026-05-02 00:16:28 +00:00

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.
Description
No description provided
Readme 4.2 GiB
Languages
C++ 30.7%
C 30.2%
Ada 14.4%
D 6.1%
Go 5.7%
Other 12.4%