From nobody Thu Jan 19 23:11:13 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NydfX4gFbz2sy7D for ; Thu, 19 Jan 2023 23:11:16 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NydfX31jXz4Qdy for ; Thu, 19 Jan 2023 23:11:16 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-wm1-f45.google.com with SMTP id l41-20020a05600c1d2900b003daf986faaeso2454732wms.3 for ; Thu, 19 Jan 2023 15:11:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hNyihUG+xqV0Jr16I7HNSjlPlaecKCo3MYRwsLarIfc=; b=7dw9IY3xFMZh3Qhp1EaVUdp3W2TbRQKsBoGkrpHPDCNHin2O2k6mSEHTqloMP83xdJ /QlBQ2poxB1G48Lms/P+/AC7cL/8jVWY+C3LEGuje3xY1navPD6EQqPzaDUYiY5VscKn /sBrIdCKJs935vFccuynYQccmFkzilcsNvQW6Oa8uzNpf2ptzImw5XvJyaH/kb3b65x/ 3ebug7OEM5BxDa5vWQc3qIGXzKdSspPuUUIXqgoKP9EDDOM3Kt55Q1JHFhvFxOi7xOzu m3lvV1vJ/VTTW2gtrcspikBESFciNItbrlrXveOGBJe2ROwxMKyQJFWpFCnhxe3pMXV7 Tbzw== X-Gm-Message-State: AFqh2krG2Uw/sXG+PWAOxlY0/2IwGpsk1Uy3FBX7zI1Jst8jvH9AjnCT 7bgHlvAdTPvRBGjMh3xibyjZjw== X-Google-Smtp-Source: AMrXdXsgYNhPQkKfBv4Ico8VFslQe9fCTflxBQnYq6AWOARVAYHPHiYow/IqzyrTcQnTzp8xMPWVhg== X-Received: by 2002:a05:600c:600e:b0:3c6:e62e:2e74 with SMTP id az14-20020a05600c600e00b003c6e62e2e74mr8200340wmb.15.1674169874533; Thu, 19 Jan 2023 15:11:14 -0800 (PST) Received: from smtpclient.apple (global-5-143.n-2.net.cam.ac.uk. [131.111.5.143]) by smtp.gmail.com with ESMTPSA id v7-20020a05600c444700b003db06493ee7sm456472wmn.47.2023.01.19.15.11.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jan 2023 15:11:14 -0800 (PST) Content-Type: text/plain; charset=utf-8 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: git: 43703bc489ec - main - stdlib.h: Fix qsort_r compatibility with GCC 12. From: Jessica Clarke In-Reply-To: <202301192249.30JMnCXf040410@gitrepo.freebsd.org> Date: Thu, 19 Jan 2023 23:11:13 +0000 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: References: <202301192249.30JMnCXf040410@gitrepo.freebsd.org> To: John Baldwin X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Rspamd-Queue-Id: 4NydfX31jXz4Qdy X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On 19 Jan 2023, at 22:49, John Baldwin wrote: >=20 > The branch main has been updated by jhb: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3D43703bc489ec504b947b869045c492ed= 38c1a69c >=20 > commit 43703bc489ec504b947b869045c492ed38c1a69c > Author: John Baldwin > AuthorDate: 2023-01-19 22:48:52 +0000 > Commit: John Baldwin > CommitDate: 2023-01-19 22:48:52 +0000 >=20 > stdlib.h: Fix qsort_r compatibility with GCC 12. >=20 > GCC 12 (unlike GCC 9) does not match a function argument passed to = the > old qsort_r() API (as is used in the qsort_r_compat test) to a > function pointer type via __generic. It treats the function type = as a > distinct type from a function pointer. As a workaround, add a = second > definition of qsort_r for GCC 12 which uses the bare function type. As far as I can tell both versions of GCC behave the same. The difference is whether __generic is using _Generic or __builtin_choose_expr with __builtin_types_compatible_p, since function and function pointer types are not compatible. Clang will take the __has_extension path, but GCC will take the builtins path, and so Clang works but GCC doesn=E2=80=99t. As a result of this change you=E2=80=99ve likely broken code that does qsort_r(..., &f) as that will have the opposite problem. The right fix is to force arg5 to decay, such as by (ab)using the comma operator with __generic((0, arg5), ...). I guess that probably belongs in the fallback implementation of __generic though, not here, which would give the following real fix: diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index 83ba7584e5b9..f7eff4768151 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -312,6 +312,9 @@ * __generic(). Unlike _Generic(), this macro can only distinguish * between a single type, so it requires nested invocations to * distinguish multiple cases. + * + * Note that the comma operator is used to force expr to decay in order = to + * match _Generic. */ =20 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >=3D 201112L) || \ @@ -321,7 +324,7 @@ #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) #define __generic(expr, t, yes, no) = \ __builtin_choose_expr( = \ - __builtin_types_compatible_p(__typeof(expr), t), yes, no) + __builtin_types_compatible_p(__typeof((0, expr)), t), yes, = no) #endif =20 /* Does that work instead for you after reverting this commit? Jess > Reviewed by: emaste > Differential Revision: https://reviews.freebsd.org/D37410 > --- > include/stdlib.h | 6 ++++++ > 1 file changed, 6 insertions(+) >=20 > diff --git a/include/stdlib.h b/include/stdlib.h > index 754e8f5f5fd4..30d24aea1c10 100644 > --- a/include/stdlib.h > +++ b/include/stdlib.h > @@ -352,9 +352,15 @@ void __qsort_r_compat(void *, size_t, size_t, = void *, > __sym_compat(qsort_r, __qsort_r_compat, FBSD_1.0); > #endif > #if defined(__generic) && !defined(__cplusplus) > +#if __GNUC__ =3D=3D 12 > +#define qsort_r(base, nel, width, arg4, arg5) = \ > + __generic(arg5, int (void *, const void *, const void *), = \ > + __qsort_r_compat, qsort_r)(base, nel, width, arg4, arg5) > +#else > #define qsort_r(base, nel, width, arg4, arg5) = \ > __generic(arg5, int (*)(void *, const void *, const void *), = \ > __qsort_r_compat, qsort_r)(base, nel, width, arg4, arg5) > +#endif > #elif defined(__cplusplus) > __END_DECLS > extern "C++" {