commit: 85471c97929d3dfb52f80c556f1803d099dfc01c Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Wed May 8 14:55:04 2024 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Wed May 8 14:55:04 2024 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=85471c97
sys-devel/gcc: backport fix for Emacs tests to 14.1.0 This _just_ missed the 14.1 release as it got reported a few hours before the tag was made. Part of Emacs is miscompiled without this and it causes test failures, so let's pull in the fix now. Bug: https://gcc.gnu.org/PR14965 Signed-off-by: Sam James <sam <AT> gentoo.org> .../gcc/files/gcc-14.1.0-emacs-PR114965.patch | 106 +++++++++++++++++++++ sys-devel/gcc/gcc-14.1.0-r1.ebuild | 54 +++++++++++ 2 files changed, 160 insertions(+) diff --git a/sys-devel/gcc/files/gcc-14.1.0-emacs-PR114965.patch b/sys-devel/gcc/files/gcc-14.1.0-emacs-PR114965.patch new file mode 100644 index 000000000000..df4fcee90c51 --- /dev/null +++ b/sys-devel/gcc/files/gcc-14.1.0-emacs-PR114965.patch @@ -0,0 +1,106 @@ +https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=d54151df3ba0ee3203e0b8cb8f8fcd168a766c51 +https://gcc.gnu.org/PR114965 + +From d54151df3ba0ee3203e0b8cb8f8fcd168a766c51 Mon Sep 17 00:00:00 2001 +From: Jakub Jelinek <[email protected]> +Date: Wed, 8 May 2024 10:17:32 +0200 +Subject: [PATCH] reassoc: Fix up optimize_range_tests_to_bit_test [PR114965] + +The optimize_range_tests_to_bit_test optimization normally emits a range +test first: + if (entry_test_needed) + { + tem = build_range_check (loc, optype, unshare_expr (exp), + false, lowi, high); + if (tem == NULL_TREE || is_gimple_val (tem)) + continue; + } +so during the bit test we already know that exp is in the [lowi, high] +range, but skips it if we have range info which tells us this isn't +necessary. +Also, normally it emits shifts by exp - lowi counter, but has an +optimization to use just exp counter if the mask isn't a more expensive +constant in that case and lowi is > 0 and high is smaller than prec. + +The following testcase is miscompiled because the two abnormal cases +are triggered. The range of exp is [43, 43][48, 48][95, 95], so we on +64-bit arch decide we don't need the entry test, because 95 - 43 < 64. +And we also decide to use just exp as counter, because the range test +tests just for exp == 43 || exp == 48, so high is smaller than 64 too. +Because 95 is in the exp range, we can't do that, we'd either need to +do a range test first, i.e. +if (exp - 43U <= 48U - 43U) if ((1UL << exp) & mask1)) +or need to subtract lowi from the shift counter, i.e. +if ((1UL << (exp - 43)) & mask2) +but can't do both unless r.upper_bound () is < prec. + +The following patch ensures that. + +2024-05-08 Jakub Jelinek <[email protected]> + + PR tree-optimization/114965 + * tree-ssa-reassoc.cc (optimize_range_tests_to_bit_test): Don't try to + optimize away exp - lowi subtraction from shift count unless entry + test is emitted or unless r.upper_bound () is smaller than prec. + + * gcc.c-torture/execute/pr114965.c: New test. + +(cherry picked from commit 9adec2d91e62a479474ae79df5b455fd4b8463ba) +--- + .../gcc.c-torture/execute/pr114965.c | 30 +++++++++++++++++++ + gcc/tree-ssa-reassoc.cc | 3 +- + 2 files changed, 32 insertions(+), 1 deletion(-) + create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr114965.c + +diff --git a/gcc/testsuite/gcc.c-torture/execute/pr114965.c b/gcc/testsuite/gcc.c-torture/execute/pr114965.c +new file mode 100644 +index 000000000000..89d68e187015 +--- /dev/null ++++ b/gcc/testsuite/gcc.c-torture/execute/pr114965.c +@@ -0,0 +1,30 @@ ++/* PR tree-optimization/114965 */ ++ ++static void ++foo (const char *x) ++{ ++ ++ char a = '0'; ++ while (1) ++ { ++ switch (*x) ++ { ++ case '_': ++ case '+': ++ a = *x; ++ x++; ++ continue; ++ default: ++ break; ++ } ++ break; ++ } ++ if (a == '0' || a == '+') ++ __builtin_abort (); ++} ++ ++int ++main () ++{ ++ foo ("_"); ++} +diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc +index 61f54f07b577..556ecdebe2d7 100644 +--- a/gcc/tree-ssa-reassoc.cc ++++ b/gcc/tree-ssa-reassoc.cc +@@ -3418,7 +3418,8 @@ optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length, + We can avoid then subtraction of the minimum value, but the + mask constant could be perhaps more expensive. */ + if (compare_tree_int (lowi, 0) > 0 +- && compare_tree_int (high, prec) < 0) ++ && compare_tree_int (high, prec) < 0 ++ && (entry_test_needed || wi::ltu_p (r.upper_bound (), prec))) + { + int cost_diff; + HOST_WIDE_INT m = tree_to_uhwi (lowi); +-- +2.39.3 diff --git a/sys-devel/gcc/gcc-14.1.0-r1.ebuild b/sys-devel/gcc/gcc-14.1.0-r1.ebuild new file mode 100644 index 000000000000..bf8cde2986d2 --- /dev/null +++ b/sys-devel/gcc/gcc-14.1.0-r1.ebuild @@ -0,0 +1,54 @@ +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +TOOLCHAIN_PATCH_DEV="sam" +PATCH_GCC_VER="14.1.0" +PATCH_VER="1" +MUSL_VER="1" +MUSL_GCC_VER="14.1.0" +PYTHON_COMPAT=( python3_{10..12} ) + +if [[ -n ${TOOLCHAIN_GCC_RC} ]] ; then + # Cheesy hack for RCs + MY_PV=$(ver_cut 1).$((($(ver_cut 2) + 1))).$((($(ver_cut 3) - 1)))-RC-$(ver_cut 5) + MY_P=${PN}-${MY_PV} + GCC_TARBALL_SRC_URI="mirror://gcc/snapshots/${MY_PV}/${MY_P}.tar.xz" + TOOLCHAIN_SET_S=no + S="${WORKDIR}"/${MY_P} +fi + +inherit toolchain + +if tc_is_live ; then + # Needs to be after inherit (for now?), bug #830908 + EGIT_BRANCH=releases/gcc-$(ver_cut 1) +elif [[ -z ${TOOLCHAIN_USE_GIT_PATCHES} ]] ; then + # Don't keyword live ebuilds + #KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86" + :; +fi + +if [[ ${CATEGORY} != cross-* ]] ; then + # Technically only if USE=hardened *too* right now, but no point in complicating it further. + # If GCC is enabling CET by default, we need glibc to be built with support for it. + # bug #830454 + RDEPEND="elibc_glibc? ( sys-libs/glibc[cet(-)?] )" + DEPEND="${RDEPEND}" + BDEPEND="amd64? ( >=${CATEGORY}/binutils-2.30[cet(-)?] )" +fi + +src_prepare() { + local p upstreamed_patches=( + # add them here + ) + for p in "${upstreamed_patches[@]}"; do + rm -v "${WORKDIR}/patch/${p}" || die + done + + toolchain_src_prepare + + eapply "${FILESDIR}"/gcc-14.1.0-emacs-PR114965.patch + eapply_user +}
