From nobody Thu Jan 19 23:36:05 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 4NyfCD5cdTz2t1yK for ; Thu, 19 Jan 2023 23:36:08 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 4NyfCD0QJZz3Dt7 for ; Thu, 19 Jan 2023 23:36:08 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of jrtc27@jrtc27.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=jrtc27@jrtc27.com; dmarc=none Received: by mail-wm1-f54.google.com with SMTP id e19-20020a05600c439300b003db1cac0c1fso3236976wmn.5 for ; Thu, 19 Jan 2023 15:36:08 -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=0E5blZrwouTbMzb5jg+vbAyiqrzXujdiKqNsy19G0Mk=; b=yTyw/fUI34jDcDxEqHI7CMPcGpUZwN0NSx9OomespDCfrl16i77yd1iE99nHnQ94bQ CrI23wTQckwaW3sgml2b6XDw1hrsj2lwXV6XZ7qr1jKPT/vbcRBRYC/b3TWrF2DJ9fX3 4+NImufmH0dk9sXUYoS+tUQG8gNbAsi4MoGM+4DYfUvXJ2pjWY5nZqO00zQhrl4AQFwK xQPavvsY5Zg/rtexAebGWjZ4UXS2k70bd8j/wBxtPOZzMyxodijR3HUXHugxq6ZjNHkM BCsdOj6VzC5CNmVCCXrnltJrid3CevvRlbtI0FXrB/dbQmjw50ep3hQoSz3gwpZp46BS 53cw== X-Gm-Message-State: AFqh2ko2bBwrpQKf26lUNEbkbYAQE+uyrNvINlts9wfhiNgk+CAk+JYc TF8GIHMKoaVfduQOQnud8Upha+Tvg85FvExw+x6w2Q== X-Google-Smtp-Source: AMrXdXuVKkC+sxHkt9mdoKLVkUY/atpqdKmCsmZ79pR9KGZHC/cWb8qcvYv/LJh2JO7pzBObF1R+uw== X-Received: by 2002:a05:600c:33a8:b0:3d9:ed3b:5b3e with SMTP id o40-20020a05600c33a800b003d9ed3b5b3emr11567466wmp.19.1674171366754; Thu, 19 Jan 2023 15:36:06 -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 g10-20020a05600c310a00b003d99da8d30asm527240wmo.46.2023.01.19.15.36.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jan 2023 15:36:06 -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: <8C902ED3-D9F8-4F88-8D43-F8E4809C9D44@freebsd.org> Date: Thu, 19 Jan 2023 23:36:05 +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: <0F50986C-BC29-4A7A-89F0-DAB3863BF51B@freebsd.org> References: <202301192249.30JMnCXf040410@gitrepo.freebsd.org> <8C902ED3-D9F8-4F88-8D43-F8E4809C9D44@freebsd.org> To: John Baldwin X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spamd-Result: default: False [-2.50 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.998]; MV_CASE(0.50)[]; FORGED_SENDER(0.30)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17:c]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_THREE(0.00)[4]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-main@freebsd.org]; TO_DN_EQ_ADDR_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DMARC_NA(0.00)[freebsd.org]; RCVD_IN_DNSWL_NONE(0.00)[209.85.128.54:from]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FREEFALL_USER(0.00)[jrtc27]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-main@freebsd.org]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; R_DKIM_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.128.54:from] X-Rspamd-Queue-Id: 4NyfCD0QJZz3Dt7 X-Spamd-Bar: -- X-ThisMailContainsUnwantedMimeParts: N On 19 Jan 2023, at 23:31, Jessica Clarke wrote: >=20 > On 19 Jan 2023, at 23:11, Jessica Clarke wrote: >>=20 >> 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. >>=20 >> 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. >>=20 >> 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: >>=20 >> 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) >=20 > With (expr) instead of expr, of course... And as for why GCC 9 works: It doesn=E2=80=99t. The tests just aren=E2=80=99t built because = MK_CXX=3Dno disables MK_TESTS. GCC 12 only hits it because it=E2=80=99s new enough to be able = to build libc++ and not force MK_CXX=3Dno. It would be nice to unpick that... Jess > Jess >=20 >> #endif >>=20 >> /* >>=20 >> Does that work instead for you after reverting this commit? >>=20 >> Jess >>=20 >>> 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++" {