From nobody Thu Jan 19 23:31:30 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 4Nyf5y07ptz2t1L7 for ; Thu, 19 Jan 2023 23:31:34 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 4Nyf5x1Q6Sz3D2G for ; Thu, 19 Jan 2023 23:31:33 +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.221.42 as permitted sender) smtp.mailfrom=jrtc27@jrtc27.com; dmarc=none Received: by mail-wr1-f42.google.com with SMTP id q10so3405695wrs.2 for ; Thu, 19 Jan 2023 15:31:33 -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=9XHDxxph9npO1ci8/XwVp8KvjPPWrleqGDgxEhFaCTI=; b=YS6aJCNcsWzbdORlDdOJ4Lvd5K3fLHd9U8gP1YjTBiu71oGB/BYZ27GJxKlML6xH7z p8JocgaiagCgH+i6WkajjWPD5cOGvsz9tsgier+v7AskA2D3VYU9p++dDSOmhUOzUVDf zbYIH0AihxFVUmfSsILRvND+fT9o66XrOmUewFKB4sQB4alKS/ei8qJ5nB7GUip3+PTw oh27i+5Ai6haYKaFqJTzGcQw+nJQu6klwJY4aDixsMzJvLkKItg161qAyisk10zjlwgW PJwcYFkGVLTv9//j1vU85zhZ42BCC2W516am6RiVR3oTUXwdMosWPev8p5lnGnO3Etb9 yEYA== X-Gm-Message-State: AFqh2koW5CRZeSMccpLiGR6/JIRPzUUNPnsc9qC9z08QnfXgxFIJv9ey AALWWohzStJ89QeqkaXrEWZu8A== X-Google-Smtp-Source: AMrXdXvJenTA5AayZFD4lpbH6aHgPW89ikniVCpM1QTO9CvD93/KT0EebwayKSwWYnpKIqqE1RNy1g== X-Received: by 2002:adf:e6cc:0:b0:2be:53d1:51ce with SMTP id y12-20020adfe6cc000000b002be53d151cemr884355wrm.37.1674171091671; Thu, 19 Jan 2023 15:31:31 -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 r9-20020adff709000000b00291f1a5ced6sm13911907wrp.53.2023.01.19.15.31.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jan 2023 15:31:31 -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: Date: Thu, 19 Jan 2023 23:31:30 +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: <8C902ED3-D9F8-4F88-8D43-F8E4809C9D44@freebsd.org> References: <202301192249.30JMnCXf040410@gitrepo.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]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_THREE(0.00)[4]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-main@freebsd.org]; TO_DN_EQ_ADDR_SOME(0.00)[]; DMARC_NA(0.00)[freebsd.org]; FROM_HAS_DN(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[209.85.221.42:from]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FREEFALL_USER(0.00)[jrtc27]; MIME_TRACE(0.00)[0:+]; MLMMJ_DEST(0.00)[dev-commits-src-main@freebsd.org]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; R_DKIM_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; MID_RHS_MATCH_FROM(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.221.42:from] X-Rspamd-Queue-Id: 4Nyf5x1Q6Sz3D2G X-Spamd-Bar: -- X-ThisMailContainsUnwantedMimeParts: N 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) With (expr) instead of expr, of course... Jess > #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++" {