From d2facc542948cfb79193220e7beb9d1c9837df8a Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 19 Nov 2024 03:48:42 +0000 Subject: sys-devel/gcc: backport C23 fix to 15.0.0_pre20241117 Backport a -std=gnu23/-std=c23 fix to 15.0.0_pre20241117 which prevented coersion from _Bool to NULL. Note that this is still dodgy code and some are proposing this be banned in a future C version (maybe even C2y), but it shouldn't be rejected in this version at least. I've added Closes tags for all bugs which, at a glance, look related, but I haven't re-tested them all and one or two might need reopening. Bug: https://gcc.gnu.org/PR112556 Closes: https://bugs.gentoo.org/943862 Closes: https://bugs.gentoo.org/943861 Closes: https://bugs.gentoo.org/943843 Closes: https://bugs.gentoo.org/943811 Closes: https://bugs.gentoo.org/943809 Closes: https://bugs.gentoo.org/943753 Closes: https://bugs.gentoo.org/943715 Closes: https://bugs.gentoo.org/943704 Closes: https://bugs.gentoo.org/942958 Signed-off-by: Sam James --- ...llow-bool-and-enum-null-pointer-constants.patch | 244 +++++++++++++++++++++ sys-devel/gcc/gcc-15.0.0_pre20241117-r2.ebuild | 54 +++++ 2 files changed, 298 insertions(+) create mode 100644 sys-devel/gcc/files/gcc-15.0.0_pre20241117-PR112556-c-Allow-bool-and-enum-null-pointer-constants.patch create mode 100644 sys-devel/gcc/gcc-15.0.0_pre20241117-r2.ebuild (limited to 'sys-devel') diff --git a/sys-devel/gcc/files/gcc-15.0.0_pre20241117-PR112556-c-Allow-bool-and-enum-null-pointer-constants.patch b/sys-devel/gcc/files/gcc-15.0.0_pre20241117-PR112556-c-Allow-bool-and-enum-null-pointer-constants.patch new file mode 100644 index 000000000000..b17c1e04998c --- /dev/null +++ b/sys-devel/gcc/files/gcc-15.0.0_pre20241117-PR112556-c-Allow-bool-and-enum-null-pointer-constants.patch @@ -0,0 +1,244 @@ +From 3d525fce70fa0ffa0b22af6e213643e1ceca5ab5 Mon Sep 17 00:00:00 2001 +Message-ID: <3d525fce70fa0ffa0b22af6e213643e1ceca5ab5.1731987909.git.sam@gentoo.org> +From: Joseph Myers +Date: Mon, 18 Nov 2024 22:24:48 +0000 +Subject: [PATCH] c: Allow bool and enum null pointer constants [PR112556] + +As reported in bug 112556, GCC wrongly rejects conversion of null +pointer constants with bool or enum type to pointers in +convert_for_assignment (assignment, initialization, argument passing, +return). Fix the code there to allow BOOLEAN_TYPE and ENUMERAL_TYPE; +it already allowed INTEGER_TYPE and BITINT_TYPE. + +This bug (together with -std=gnu23 meaning false has type bool rather +than int) has in turn resulted in people thinking they need to fix +code using false as a null pointer constant for C23 compatibility. +While such a usage is certainly questionable, it has nothing to do +with C23 compatibility and the right place for warnings about such +usage is -Wzero-as-null-pointer-constant. I think it would be +appropriate to extend -Wzero-as-null-pointer-constant to cover +BOOLEAN_TYPE, ENUMERAL_TYPE and BITINT_TYPE (in all the various +contexts in which that option generates warnings), though this patch +doesn't do anything about that option. + +Bootstrapped with no regressions for x86-64-pc-linux-gnu. + + PR c/112556 + +gcc/c/ + * c-typeck.cc (convert_for_assignment): Allow conversion of + ENUMERAL_TYPE and BOOLEAN_TYPE null pointer constants to pointers. + +gcc/testsuite/ + * gcc.dg/c11-null-pointer-constant-1.c, + gcc.dg/c23-null-pointer-constant-1.c: New tests. +--- + gcc/c/c-typeck.cc | 2 + + .../gcc.dg/c11-null-pointer-constant-1.c | 55 ++++++++ + .../gcc.dg/c23-null-pointer-constant-1.c | 120 ++++++++++++++++++ + 3 files changed, 177 insertions(+) + create mode 100644 gcc/testsuite/gcc.dg/c11-null-pointer-constant-1.c + create mode 100644 gcc/testsuite/gcc.dg/c23-null-pointer-constant-1.c + +diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc +index 26ee0ebf91f0..a701dd090fb8 100644 +--- a/gcc/c/c-typeck.cc ++++ b/gcc/c/c-typeck.cc +@@ -8457,6 +8457,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, + } + else if (codel == POINTER_TYPE + && (coder == INTEGER_TYPE ++ || coder == ENUMERAL_TYPE ++ || coder == BOOLEAN_TYPE + || coder == NULLPTR_TYPE + || coder == BITINT_TYPE)) + { +diff --git a/gcc/testsuite/gcc.dg/c11-null-pointer-constant-1.c b/gcc/testsuite/gcc.dg/c11-null-pointer-constant-1.c +new file mode 100644 +index 000000000000..f463a1a59da3 +--- /dev/null ++++ b/gcc/testsuite/gcc.dg/c11-null-pointer-constant-1.c +@@ -0,0 +1,55 @@ ++/* Test zero with different types as null pointer constant: bug 112556. */ ++/* { dg-do compile } */ ++/* { dg-options "-std=c11 -pedantic-errors -Wno-pointer-compare" } */ ++ ++enum e { ZERO }; ++ ++void *p1 = 0; ++void *p2 = 0LL; ++void *p3 = (char) 0; ++void *p4 = 0UL; ++void *p5 = (_Bool) 0; ++void *p6 = (enum e) ZERO; ++ ++void f (void *); ++ ++void * ++g (void) ++{ ++ p1 = 0; ++ p2 = 0LL; ++ p3 = (char) 0; ++ p4 = 0UL; ++ p5 = (_Bool) 0; ++ p6 = (enum e) ZERO; ++ f (0); ++ f (0ULL); ++ f (0L); ++ f ((char) 0); ++ f ((_Bool) 0); ++ f ((enum e) ZERO); ++ (1 ? p1 : 0); ++ (1 ? p1 : 0L); ++ (1 ? p1 : 0ULL); ++ (1 ? p1 : (char) 0); ++ (1 ? p1 : (_Bool) 0); ++ (1 ? p1 : (enum e) 0); ++ p1 == 0; ++ p1 == 0LL; ++ p1 == 0U; ++ p1 == (char) 0; ++ p1 == (_Bool) 0; ++ p1 == (enum e) 0; ++ p1 != 0; ++ p1 != 0LL; ++ p1 != 0U; ++ p1 != (char) 0; ++ p1 != (_Bool) 0; ++ p1 != (enum e) 0; ++ return 0; ++ return 0UL; ++ return 0LL; ++ return (char) 0; ++ return (_Bool) 0; ++ return (enum e) 0; ++} +diff --git a/gcc/testsuite/gcc.dg/c23-null-pointer-constant-1.c b/gcc/testsuite/gcc.dg/c23-null-pointer-constant-1.c +new file mode 100644 +index 000000000000..71b66cc35d6b +--- /dev/null ++++ b/gcc/testsuite/gcc.dg/c23-null-pointer-constant-1.c +@@ -0,0 +1,120 @@ ++/* Test zero with different types as null pointer constant: bug 112556. */ ++/* { dg-do compile } */ ++/* { dg-options "-std=c23 -pedantic-errors -Wno-pointer-compare" } */ ++ ++enum e { ZERO }; ++enum e2 : bool { BZERO }; ++enum e3 : long { LZERO }; ++ ++void *p1 = 0; ++void *p2 = 0LL; ++void *p3 = (char) 0; ++void *p4 = 0UL; ++void *p5 = (bool) 0; ++void *p6 = (enum e) ZERO; ++void *p7 = false; ++void *p8 = BZERO; ++void *p9 = (enum e2) 0; ++void *p10 = LZERO; ++void *p11 = (enum e3) 0; ++#ifdef __BITINT_MAXWIDTH__ ++void *p12 = 0wb; ++void *p13 = 0uwb; ++#endif ++ ++void f (void *); ++ ++void * ++g (void) ++{ ++ p1 = 0; ++ p2 = 0LL; ++ p3 = (char) 0; ++ p4 = 0UL; ++ p5 = (bool) 0; ++ p6 = (enum e) ZERO; ++ p7 = false; ++ p8 = BZERO; ++ p9 = (enum e2) 0; ++ p10 = LZERO; ++ p11 = (enum e3) 0; ++#ifdef __BITINT_MAXWIDTH__ ++ p12 = 0wb; ++ p13 = 0uwb; ++#endif ++ f (0); ++ f (0ULL); ++ f (0L); ++ f ((char) 0); ++ f ((bool) 0); ++ f ((enum e) ZERO); ++ f (false); ++ f (BZERO); ++ f ((enum e2) 0); ++ f (LZERO); ++ f ((enum e3) 0); ++#ifdef __BITINT_MAXWIDTH__ ++ f (0wb); ++ f (0uwb); ++#endif ++ (1 ? p1 : 0); ++ (1 ? p1 : 0L); ++ (1 ? p1 : 0ULL); ++ (1 ? p1 : (char) 0); ++ (1 ? p1 : (bool) 0); ++ (1 ? p1 : (enum e) 0); ++ (1 ? p1 : false); ++ (1 ? p1 : BZERO); ++ (1 ? p1 : (enum e2) 0); ++ (1 ? p1 : LZERO); ++ (1 ? p1 : (enum e3) 0); ++#ifdef __BITINT_MAXWIDTH__ ++ (1 ? p1 : 0wb); ++ (1 ? p1 : 0uwb); ++#endif ++ p1 == 0; ++ p1 == 0LL; ++ p1 == 0U; ++ p1 == (char) 0; ++ p1 == (bool) 0; ++ p1 == (enum e) 0; ++ p1 == false; ++ p1 == BZERO; ++ p1 == (enum e2) 0; ++ p1 == LZERO; ++ p1 == (enum e3) 0; ++#ifdef __BITINT_MAXWIDTH__ ++ p1 == 0wb; ++ p1 == 0uwb; ++#endif ++ p1 != 0; ++ p1 != 0LL; ++ p1 != 0U; ++ p1 != (char) 0; ++ p1 != (bool) 0; ++ p1 != (enum e) 0; ++ p1 != false; ++ p1 != BZERO; ++ p1 != (enum e2) 0; ++ p1 != LZERO; ++ p1 != (enum e3) 0; ++#ifdef __BITINT_MAXWIDTH__ ++ p1 != 0wb; ++ p1 != 0uwb; ++#endif ++ return 0; ++ return 0UL; ++ return 0LL; ++ return (char) 0; ++ return (bool) 0; ++ return (enum e) 0; ++ return false; ++ return BZERO; ++ return (enum e2) 0; ++ return LZERO; ++ return (enum e3) 0; ++#ifdef __BITINT_MAXWIDTH__ ++ return 0wb; ++ return 0uwb; ++#endif ++} +-- +2.47.0 diff --git a/sys-devel/gcc/gcc-15.0.0_pre20241117-r2.ebuild b/sys-devel/gcc/gcc-15.0.0_pre20241117-r2.ebuild new file mode 100644 index 000000000000..ee327823124e --- /dev/null +++ b/sys-devel/gcc/gcc-15.0.0_pre20241117-r2.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" +TOOLCHAIN_HAS_TESTS=1 +PATCH_GCC_VER="15.0.0" +PATCH_VER="26" +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}-PR112556-c-Allow-bool-and-enum-null-pointer-constants.patch + eapply_user +} -- cgit v1.2.3-65-gdbad