From nobody Sun Aug 6 21:27:40 2023 X-Original-To: dev-commits-src-all@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 4RJsx86xfKz4mS1R; Sun, 6 Aug 2023 21:27:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RJsx86FChz4vl9; Sun, 6 Aug 2023 21:27:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691357260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L1vpxBKHaNiQ/nzg7bg1iLD66g5iXOPlURM8yvH7mYk=; b=hkwsO7P0bWa9BNo9L+3vI6euSSlrrIt87Jjon5liShkrz9vhaae3oBzRHCKS5Tpmc1vYrT 9G3p26XTwiOCyFUL355pfAWaUkg4/tnZFjLBEKcKWsXo7YAoxujK7w+Vx9v7f48+ZKf1Eh N7KTRMuRXYP2Y7tDCUR9nfhzRmNalyJsIDxNNTAi4NAsWc7qWUQ6sLSkbygxb2m4Mch3wd hnfJ06dSZSImQvpMlvVvrtbSDfU4vCx5ag2i/NR81KJtCwN40LmSVWhHSz3iZq2lBu32pp 8XzXMww80DvVt4Cg26NOF551LrfAo/8ktHHt555Yfjs5oun4QxzT9TWHIbgiXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691357260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L1vpxBKHaNiQ/nzg7bg1iLD66g5iXOPlURM8yvH7mYk=; b=ojUsCJeiBswNeIhsE3RCxIK/tDeej+5CqqKgAppiZe+xR54nNeRpU9nSnSFUXNutkLAOW7 iu3T20f8BUt5IVLIUi24LDSvXwxSu/6tPVUn5kdQulMXxf92TMQXMswbiXXBvpZ2QTLeWH f/14BUA9asTlTKSSDsMdprDDgCq6IOWkYMgtI8Oymyo0GYhAXPvnKnjJKThSLfRHnyci8S H0GE3zKAdoiTSYd57axK6QL7SbGPljm+orKwV67JpnC+O4XtTAOUOiEcD3x0VGPSwqPU9d 90pbny1Bl5o43+l8DeEPrhnOfMt7uB7RcqO3TVFbVg9Gs+wRjwz7QJJ0r2PW7g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691357260; a=rsa-sha256; cv=none; b=Z5fqCjP1wkE7HFlOkSZ5xKZv2rPHKKV8gvFj8kP0arD53eAtxjZLWbpnzGoQIztzCPbeoM Gx6TIRdzc3ulyQyY4hgUaHYNuypc4d+Btjjjve7z0c3VdDJRz6NKWBmQkd9nh9wR2Rdqaj eyRCKohdfGLICYMjYavA7Okx/KwLhl+KymwAfTOsJantLYuHF1E9+pEEs0qAxLAKo3HhVK zOigT3tzxTX6DKx2fB2Tc+PmPgHpFRxDffwS/9lNEaWZNKszleVqKPZzp0CnHnpZfOlpsG JU5J+4MuOPVPJW+6M2F9kWdJ6WwQv33JWOtIJWjZCnStWVTIsVIutUuyifnmkg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RJsx855xPzBTX; Sun, 6 Aug 2023 21:27:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 376LReTe026247; Sun, 6 Aug 2023 21:27:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 376LRei9026246; Sun, 6 Aug 2023 21:27:40 GMT (envelope-from git) Date: Sun, 6 Aug 2023 21:27:40 GMT Message-Id: <202308062127.376LRei9026246@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 15876d9fd83f - main - sys/cdefs.h: fix for use __restrict in C++ List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 15876d9fd83fdfa7d541ea747eb40faeade975d2 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=15876d9fd83fdfa7d541ea747eb40faeade975d2 commit 15876d9fd83fdfa7d541ea747eb40faeade975d2 Author: Sebastian Huber AuthorDate: 2023-08-06 13:27:27 +0000 Commit: Konstantin Belousov CommitDate: 2023-08-06 21:09:52 +0000 sys/cdefs.h: fix for use __restrict in C++ Newlib shares large parts of with FreeBSD and received this bug report: https://sourceware.org/pipermail/newlib/2023/020400.html As an extension, GCC and clang offer C99-style restricted pointers in C++ mode: https://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html We notice that this extension is broken when including newlib headers: restricted pointers are treated as ordinary pointers. We traced this to the following section of newlib/libc/include/sys/cdefs.h: /* * GCC 2.95 provides `__restrict' as an extension to C90 to support the * C99-specific `restrict' type qualifier. We happen to use `__restrict' as * a way to define the `restrict' type qualifier without disturbing older * software that is unaware of C99 keywords. */ #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 #define __restrict #else #define __restrict restrict #endif #endif While the GCC __restrict extension was indeed introduced in GCC 2.95, it is not limited to this version; the extension is also not limited to C90: https://gcc.gnu.org/gcc-2.95/c++features.html Rewrite the logic in the header so that __restrict is kept alone when available. PR: 272723 MFC after: 1 week --- sys/sys/cdefs.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index 1de042339c3a..797460c08db8 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -403,17 +403,15 @@ #endif /* - * GCC 2.95 provides `__restrict' as an extension to C90 to support the - * C99-specific `restrict' type qualifier. We happen to use `__restrict' as - * a way to define the `restrict' type qualifier without disturbing older - * software that is unaware of C99 keywords. + * We use `__restrict' as a way to define the `restrict' type qualifier + * without disturbing older software that is unaware of C99 keywords. + * GCC also provides `__restrict' as an extension to support C99-style + * restricted pointers in other language modes. */ -#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) -#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 -#define __restrict -#else +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 #define __restrict restrict -#endif +#elif !__GNUC_PREREQ__(2, 95) +#define __restrict #endif /*