public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-devel/gcc/files/, sys-devel/gcc/
Date: Wed,  8 May 2024 14:56:17 +0000 (UTC)	[thread overview]
Message-ID: <1715180104.85471c97929d3dfb52f80c556f1803d099dfc01c.sam@gentoo> (raw)

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 <jakub@redhat.com>
+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  <jakub@redhat.com>
+
+	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
+}


             reply	other threads:[~2024-05-08 14:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 14:56 Sam James [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-04-25 16:32 [gentoo-commits] repo/gentoo:master commit in: sys-devel/gcc/files/, sys-devel/gcc/ Sam James
2025-04-21  6:22 Sam James
2025-04-10 17:50 Sam James
2025-04-07  4:05 Sam James
2025-04-01 22:43 Sam James
2025-03-27 14:43 Sam James
2025-03-26 12:39 Sam James
2025-03-03 19:40 Sam James
2025-02-23  5:42 Sam James
2025-02-15  4:01 Sam James
2024-12-27 18:01 Sam James
2024-09-24  1:41 Sam James
2024-09-23 15:23 Sam James
2024-03-26 20:09 Sam James
2024-03-04 23:34 Sam James
2023-10-24  1:59 Sam James
2023-10-03 19:03 Sam James
2023-03-29  1:51 Sam James
2022-08-22  1:41 Sam James
2019-05-29 19:22 Andreas K. Hüttel
2019-05-01 17:14 Sergei Trofimovich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1715180104.85471c97929d3dfb52f80c556f1803d099dfc01c.sam@gentoo \
    --to=sam@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox