From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-devel/gcc/, sys-devel/gcc/files/
Date: Wed, 26 Feb 2025 04:06:15 +0000 (UTC) [thread overview]
Message-ID: <1740542662.d7440acce642d9131d29f1c1047411fee18c0b3c.sam@gentoo> (raw)
commit: d7440acce642d9131d29f1c1047411fee18c0b3c
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 26 04:04:22 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Feb 26 04:04:22 2025 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d7440acc
sys-devel/gcc: backport C++ PMF fix to 15.0.1_pre20250223
This backports the general fix for 2bca6ba8b0bdacccb883071046b7a9b50ce32231 which
landed yesterday. While KWin has a workaround, the pattern pops up in other
places, so let's avoid hard-to-debug problems.
Bug: https://gcc.gnu.org/PR118923
Signed-off-by: Sam James <sam <AT> gentoo.org>
...250223-c-Fix-range-for-with-PMFs-PR118923.patch | 231 +++++++++++++++++++++
sys-devel/gcc/gcc-15.0.1_pre20250223-r1.ebuild | 53 +++++
2 files changed, 284 insertions(+)
diff --git a/sys-devel/gcc/files/gcc-15.0.1_pre20250223-c-Fix-range-for-with-PMFs-PR118923.patch b/sys-devel/gcc/files/gcc-15.0.1_pre20250223-c-Fix-range-for-with-PMFs-PR118923.patch
new file mode 100644
index 000000000000..04cf198fb673
--- /dev/null
+++ b/sys-devel/gcc/files/gcc-15.0.1_pre20250223-c-Fix-range-for-with-PMFs-PR118923.patch
@@ -0,0 +1,231 @@
+From a41b3f54c13890b1327bb3d4fbae8f7feb37d00b Mon Sep 17 00:00:00 2001
+Message-ID: <a41b3f54c13890b1327bb3d4fbae8f7feb37d00b.1740542521.git.sam@gentoo.org>
+From: Jakub Jelinek <jakub@redhat.com>
+Date: Tue, 25 Feb 2025 09:26:46 +0100
+Subject: [PATCH] c++: Fix range for with PMFs [PR118923]
+
+The following testcases segfault because the new range for -frange-for-ext-temps
+temporary extension extends even the internal TARGET_EXPRs created by
+get_member_function_from_ptrfunc.
+
+The following patch fixes that by using get_internal_target_expr for those
+instead of force_target_expr (similarly in cp_finish_decl and
+build_comparison_op) and using force_target_expr inside of
+get_internal_target_expr.
+
+2025-02-25 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/118923
+ * tree.cc (get_internal_target_expr): Use force_target_expr
+ instead of build_target_expr_with_type.
+ * typeck.cc (get_member_function_from_ptrfunc): Use
+ get_internal_target_expr instead of force_target_expr.
+ * decl.cc (cp_finish_decl): Likewise.
+ * method.cc (build_comparison_op): Likewise.
+
+ * g++.dg/cpp0x/pr118923.C: New test.
+ * g++.dg/cpp1y/pr118923.C: New test.
+---
+ gcc/cp/decl.cc | 6 +--
+ gcc/cp/method.cc | 2 +-
+ gcc/cp/tree.cc | 3 +-
+ gcc/cp/typeck.cc | 6 +--
+ gcc/testsuite/g++.dg/cpp0x/pr118923.C | 66 +++++++++++++++++++++++++++
+ gcc/testsuite/g++.dg/cpp1y/pr118923.C | 38 +++++++++++++++
+ 6 files changed, 110 insertions(+), 11 deletions(-)
+ create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr118923.C
+ create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr118923.C
+
+diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
+index 05ad9bb24d59..936e48e907e2 100644
+--- a/gcc/cp/decl.cc
++++ b/gcc/cp/decl.cc
+@@ -9377,8 +9377,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
+ tree guard = NULL_TREE;
+ if (cleanups || cleanup)
+ {
+- guard = force_target_expr (boolean_type_node,
+- boolean_false_node, tf_none);
++ guard = get_internal_target_expr (boolean_false_node);
+ add_stmt (guard);
+ guard = TARGET_EXPR_SLOT (guard);
+ }
+@@ -9407,8 +9406,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
+ popped that all, so push those extra cleanups around
+ the whole sequence with a guard variable. */
+ gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
+- guard = force_target_expr (integer_type_node,
+- integer_zero_node, tf_none);
++ guard = get_internal_target_expr (integer_zero_node);
+ add_stmt (guard);
+ guard = TARGET_EXPR_SLOT (guard);
+ for (unsigned i = 0; i < n_extra_cleanups; ++i)
+diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
+index 3914bbb1ef23..05c19cf0661e 100644
+--- a/gcc/cp/method.cc
++++ b/gcc/cp/method.cc
+@@ -1597,7 +1597,7 @@ build_comparison_op (tree fndecl, bool defining, tsubst_flags_t complain)
+ /* Some other array, will need runtime loop. */
+ else
+ {
+- idx = force_target_expr (sizetype, maxval, complain);
++ idx = get_internal_target_expr (maxval);
+ loop_indexes = tree_cons (idx, NULL_TREE, loop_indexes);
+ }
+ expr_type = TREE_TYPE (expr_type);
+diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
+index 5628a576f01b..5863b6878f02 100644
+--- a/gcc/cp/tree.cc
++++ b/gcc/cp/tree.cc
+@@ -982,8 +982,7 @@ tree
+ get_internal_target_expr (tree init)
+ {
+ init = convert_bitfield_to_declared_type (init);
+- tree t = build_target_expr_with_type (init, TREE_TYPE (init),
+- tf_warning_or_error);
++ tree t = force_target_expr (TREE_TYPE (init), init, tf_warning_or_error);
+ TARGET_EXPR_INTERNAL_P (t) = true;
+ return t;
+ }
+diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
+index a9c32ff930d5..bbaca960bd7c 100644
+--- a/gcc/cp/typeck.cc
++++ b/gcc/cp/typeck.cc
+@@ -4219,16 +4219,14 @@ get_member_function_from_ptrfunc (tree *instance_ptrptr, tree function,
+ && !DECL_P (instance_ptr)
+ && !TREE_CONSTANT (instance_ptr)))
+ instance_ptr = instance_save_expr
+- = force_target_expr (TREE_TYPE (instance_ptr), instance_ptr,
+- complain);
++ = get_internal_target_expr (instance_ptr);
+
+ /* See above comment. */
+ if (TREE_SIDE_EFFECTS (function)
+ || (!nonvirtual
+ && !DECL_P (function)
+ && !TREE_CONSTANT (function)))
+- function
+- = force_target_expr (TREE_TYPE (function), function, complain);
++ function = get_internal_target_expr (function);
+
+ /* Start by extracting all the information from the PMF itself. */
+ e3 = pfn_from_ptrmemfunc (function);
+diff --git a/gcc/testsuite/g++.dg/cpp0x/pr118923.C b/gcc/testsuite/g++.dg/cpp0x/pr118923.C
+new file mode 100644
+index 000000000000..55d3052b61f3
+--- /dev/null
++++ b/gcc/testsuite/g++.dg/cpp0x/pr118923.C
+@@ -0,0 +1,66 @@
++// PR c++/118923
++// { dg-do run { target c++11 } }
++// { dg-additional-options "-frange-for-ext-temps" { target c++23 } }
++// { dg-additional-options "-fno-range-for-ext-temps" { target c++20_down } }
++
++int g;
++
++struct A {
++ int a[3];
++ A (int x, int y, int z) : a{x, y, z} { if ((g++ & 7) != 4) __builtin_abort (); }
++ A (const A &x) = delete;
++ ~A () { if ((g++ & 7) != 7 - 2 * (__cpp_range_based_for >= 202211)) __builtin_abort (); }
++ int *begin () { return a; }
++ int *end () { return a + 3; }
++};
++
++struct B {
++ B () { if ((g++ & 7) != 3) __builtin_abort (); }
++ B (const B &) = delete;
++ ~B () { if ((g++ & 7) != 5 + (__cpp_range_based_for >= 202211)) __builtin_abort (); }
++};
++
++struct C {
++ A foo (const B &) { return { 1, 2, 3 }; }
++ A bar (const B &) { return { 4, 5, 6 }; }
++ bool baz () { return b; }
++ bool b = false;
++ static C c;
++};
++
++C C::c;
++
++struct D {
++ D () { if ((g++ & 5) != 0) __builtin_abort (); }
++ D (const D &) = delete;
++ ~D () { if ((g & 7) != 1 && (g & 7) != 6 + (__cpp_range_based_for >= 202211)) __builtin_abort (); g++; }
++};
++
++inline C *
++qux (const D &)
++{
++ return &C::c;
++}
++
++void
++foo ()
++{
++ int z = 1;
++ auto d = qux (D {})->baz () ? &C::bar : &C::foo;
++ for (const int &r : (qux (D {})->*d) (B {}))
++ if (z++ != r)
++ __builtin_abort ();
++ C::c.b = true;
++ d = qux (D {})->baz () ? &C::bar : &C::foo;
++ for (const int &r : (qux (D {})->*d) (B {}))
++ if (z++ != r)
++ __builtin_abort ();
++}
++
++int
++main ()
++{
++ foo ();
++ if (g != 16)
++ __builtin_abort ();
++}
+diff --git a/gcc/testsuite/g++.dg/cpp1y/pr118923.C b/gcc/testsuite/g++.dg/cpp1y/pr118923.C
+new file mode 100644
+index 000000000000..b375f47a7d0f
+--- /dev/null
++++ b/gcc/testsuite/g++.dg/cpp1y/pr118923.C
+@@ -0,0 +1,38 @@
++// PR c++/118923
++// { dg-do run { target c++14 } }
++
++struct A {
++ int a[3] = { 0, 0, 0 };
++ int *begin () { return a; }
++ int *end () { return a + 3; }
++};
++
++struct B {
++ A foo () { return { 1, 2, 3 }; }
++ A bar () { return { 1, 2, 3 }; }
++ bool baz () { return b; }
++ bool b = false;
++ static B c;
++};
++
++B B::c;
++
++inline B *
++qux ()
++{
++ return &B::c;
++}
++
++void
++foo ()
++{
++ auto d = qux ()->baz () ? &B::foo : &B::bar;
++ for (const int &r : (qux ()->*d) ())
++ ;
++}
++
++int
++main ()
++{
++ foo ();
++}
+--
+2.48.1
+
diff --git a/sys-devel/gcc/gcc-15.0.1_pre20250223-r1.ebuild b/sys-devel/gcc/gcc-15.0.1_pre20250223-r1.ebuild
new file mode 100644
index 000000000000..a4f89c791044
--- /dev/null
+++ b/sys-devel/gcc/gcc-15.0.1_pre20250223-r1.ebuild
@@ -0,0 +1,53 @@
+# Copyright 1999-2025 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+TOOLCHAIN_PATCH_DEV="sam"
+TOOLCHAIN_HAS_TESTS=1
+PATCH_GCC_VER="15.0.0"
+PATCH_VER="46"
+MUSL_VER="2"
+MUSL_GCC_VER="15.0.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=master
+elif [[ -z ${TOOLCHAIN_USE_GIT_PATCHES} ]] ; then
+ # Don't keyword live ebuilds
+ #KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~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}"
+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}"/${P}-c-Fix-range-for-with-PMFs-PR118923.patch
+ eapply_user
+}
next reply other threads:[~2025-02-26 4:06 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-26 4:06 Sam James [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-12-23 11:57 [gentoo-commits] repo/gentoo:master commit in: sys-devel/gcc/, sys-devel/gcc/files/ Sam James
2024-11-19 3:52 Sam James
2024-06-25 0:11 Sam James
2024-03-07 18:37 Sam James
2024-02-19 5:06 Sam James
2023-10-18 19:33 Sam James
2023-05-16 6:07 Sam James
2023-05-03 12:32 Sam James
2023-04-26 14:14 Sam James
2023-04-17 12:05 Sam James
2023-04-12 13:23 Sam James
2023-04-12 7:40 Sam James
2023-04-12 7:35 Sam James
2023-04-05 1:18 Sam James
2022-08-22 1:41 Sam James
2022-08-19 18:05 Sam James
2021-11-18 5:25 Sam James
2020-02-06 19:19 Sergei Trofimovich
2019-05-03 21:49 Andreas K. Hüttel
2017-11-19 13:40 Andreas Hüttel
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=1740542662.d7440acce642d9131d29f1c1047411fee18c0b3c.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