From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 48C291582EF for ; Wed, 26 Feb 2025 04:06:18 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 335E03431B0 for ; Wed, 26 Feb 2025 04:06:18 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 372A41103AC; Wed, 26 Feb 2025 04:06:17 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id C88CC1103AC for ; Wed, 26 Feb 2025 04:06:16 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 7554B3431B0 for ; Wed, 26 Feb 2025 04:06:16 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 0A3E81236 for ; Wed, 26 Feb 2025 04:06:15 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1740542662.d7440acce642d9131d29f1c1047411fee18c0b3c.sam@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: sys-devel/gcc/, sys-devel/gcc/files/ X-VCS-Repository: repo/gentoo X-VCS-Files: sys-devel/gcc/files/gcc-15.0.1_pre20250223-c-Fix-range-for-with-PMFs-PR118923.patch sys-devel/gcc/gcc-15.0.1_pre20250223-r1.ebuild X-VCS-Directories: sys-devel/gcc/files/ sys-devel/gcc/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: d7440acce642d9131d29f1c1047411fee18c0b3c X-VCS-Branch: master Date: Wed, 26 Feb 2025 04:06:15 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 81295762-a82f-48df-9fb5-b86bb720d5ca X-Archives-Hash: 657192ae3ec1c97c7244bc42a809964c commit: d7440acce642d9131d29f1c1047411fee18c0b3c Author: Sam James gentoo org> AuthorDate: Wed Feb 26 04:04:22 2025 +0000 Commit: Sam James gentoo 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 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: +From: Jakub Jelinek +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 + + 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 +}