From nobody Sat Feb 3 19:23:57 2024 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 4TS2ct4Xszz58GNh; Sat, 3 Feb 2024 19:23:58 +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 4TS2ct1cxwz42T9; Sat, 3 Feb 2024 19:23:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706988238; 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=5Bg9bmFx+PvBM2Bez9L3BRpuU5Las+SRmQJDXGwlSOc=; b=hBAiO6kP3ibcKpLbs0FKOD1gsQJXxdZPqUNuzXXEhpLvbyG9oJPfQhUoY/0fRV7T3ctG3J x6cIL2cGkuNuNUism9Rxp8lsndBDhOWmDP1k/FSUN4nyyM8J+GYyLMb6xNL6wmt/gdF+Xr uvT8gawuU6oPlFrFpHQpHDtopvVpTjE5I9HiEEOzjJIBC2vqI3wZ6z9CU8F3aT6xR1+yrL DChWEd/X16mNbZXKBTUxAga6/RNIvJX88wslmEXPiR8l8pMck1dOv74ciqfLg02/6m7QUV v0L+o1+po5LtWt650aIdKetFXyDavZmia3jHq2Z+cYfd3sB7QqTKw1rpsHUuAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706988238; 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=5Bg9bmFx+PvBM2Bez9L3BRpuU5Las+SRmQJDXGwlSOc=; b=XOJ5RWAosObuRXDAzZadllBxkLQFyO2tgMtlMMn4TrNHNbo1uLzL8uNBMpUJ1SzwZjjkdM KjdXF1U4Ze15yAdWShplyMY+PXcypHcDDBRMtDgKC2VhmTTMBzYL2TLgnSGorjotceSxG4 eNk5geAPxxF65xFkVPUBVPJ9K6P3Go6RfDe94RScdG/pJ805A5JiAho5vN9joxhrvHHzZ0 sxtfq9MSObtpo/sXJRnsJ/cFF9C2HcIcPJsnSkHIiw4iBF3JJ/2a4nfamOrC1XOPuSyWba A2tugOC5fiYFxQmo5itGuMPjhVqn91lmG1D1EoskFBYVm3Hx2pOioKvm6UVq+Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706988238; a=rsa-sha256; cv=none; b=kNed2/oI6pUX4FcN64GQf6am8UhOyQb1BgK/QZL7NPR4hMY98aHfGPNqPQHMzWz1EAC6v9 HdU6k2eGE2Ag+3vWp+6wBVgTLsw0uZENs40pALImDC4mKQX78IZQCTVo1bHKleJ3CzHnCb n9vqfUqbsVpEIneiKp2O+XXgyaGqnnaSOwBYKskaYN3FPHOlHsbx9vCwWs2G7YmOYagPZ7 R4OErrkbyMGDSqMbYwXKnpjrmh3SNRc9FS/pq7v+BIS1Idqf9ftspuGp/wOH+wK+d4I3DM vq6YiXlTihnFrIeSnj/UAV4pN6huT4JrV37wZTBD9BVvKUKOnSEUfR6AJrjMEg== 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 4TS2ct0YY4zQvr; Sat, 3 Feb 2024 19:23:58 +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 413JNvDp012354; Sat, 3 Feb 2024 19:23:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 413JNvV5012351; Sat, 3 Feb 2024 19:23:57 GMT (envelope-from git) Date: Sat, 3 Feb 2024 19:23:57 GMT Message-Id: <202402031923.413JNvV5012351@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 9ed713d97b3d - main - cdefs: Introduce __result_use_or_ignore_check 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9ed713d97b3d0376747c9ad1842864bebf08f823 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9ed713d97b3d0376747c9ad1842864bebf08f823 commit 9ed713d97b3d0376747c9ad1842864bebf08f823 Author: Mark Johnston AuthorDate: 2024-02-03 19:16:50 +0000 Commit: Mark Johnston CommitDate: 2024-02-03 19:16:50 +0000 cdefs: Introduce __result_use_or_ignore_check Try to paper over inconsistent semantics for __warn_unused_result__ between clang and gcc. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 for a spirited discussion of these semantics. Introduce __result_use_or_ignore_check, which allows callers to explicitly ignore the return value with a cast to void. Use that to restore some checking for copyout() and friends, previously removed in commit d07acc58d898 ("systm: Relax __result_use_check annotations"). Reviewed by: olce, rpokala, kib, emaste MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D43426 --- sys/sys/cdefs.h | 11 +++++++++++ sys/sys/systm.h | 17 +++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index 206cc569c55a..e47a7072e1f1 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -326,6 +326,17 @@ #if __GNUC_PREREQ__(3, 4) #define __fastcall __attribute__((__fastcall__)) #define __result_use_check __attribute__((__warn_unused_result__)) +#ifdef __clang__ +/* + * clang and gcc have different semantics for __warn_unused_result__: the latter + * does not permit the use of a void cast to suppress the warning. Use + * __result_use_or_ignore_check in places where a void cast is acceptable. + * This can be implemented by [[nodiscard]] from C23. + */ +#define __result_use_or_ignore_check __result_use_check +#else +#define __result_use_or_ignore_check +#endif /* !__clang__ */ #else #define __fastcall #define __result_use_check diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 29c8bfc3c768..376a35e7e8e2 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -299,10 +299,11 @@ int __result_use_check copyin(const void * __restrict udaddr, void * _Nonnull __restrict kaddr, size_t len); int __result_use_check copyin_nofault(const void * __restrict udaddr, void * _Nonnull __restrict kaddr, size_t len); -int copyout(const void * _Nonnull __restrict kaddr, - void * __restrict udaddr, size_t len); -int copyout_nofault(const void * _Nonnull __restrict kaddr, +int __result_use_or_ignore_check copyout(const void * _Nonnull __restrict kaddr, void * __restrict udaddr, size_t len); +int __result_use_or_ignore_check copyout_nofault( + const void * _Nonnull __restrict kaddr, void * __restrict udaddr, + size_t len); #ifdef SAN_NEEDS_INTERCEPTORS int SAN_INTERCEPTOR(copyin)(const void *, void *, size_t); @@ -323,11 +324,11 @@ int64_t fuword64(volatile const void *base); int __result_use_check fueword(volatile const void *base, long *val); int __result_use_check fueword32(volatile const void *base, int32_t *val); int __result_use_check fueword64(volatile const void *base, int64_t *val); -int subyte(volatile void *base, int byte); -int suword(volatile void *base, long word); -int suword16(volatile void *base, int word); -int suword32(volatile void *base, int32_t word); -int suword64(volatile void *base, int64_t word); +int __result_use_or_ignore_check subyte(volatile void *base, int byte); +int __result_use_or_ignore_check suword(volatile void *base, long word); +int __result_use_or_ignore_check suword16(volatile void *base, int word); +int __result_use_or_ignore_check suword32(volatile void *base, int32_t word); +int __result_use_or_ignore_check suword64(volatile void *base, int64_t word); uint32_t casuword32(volatile uint32_t *base, uint32_t oldval, uint32_t newval); u_long casuword(volatile u_long *p, u_long oldval, u_long newval); int casueword32(volatile uint32_t *base, uint32_t oldval, uint32_t *oldvalp,