From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 584EE5C9A for ; Tue, 23 Jan 2024 20:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706042805; cv=none; b=BAFhIq/pymKiqpsHC+VBpR0UXdD/1Nut1kQk5+uidWE6SUvFud5WyahBp/3lyLk2pxuLgbV6WT8d5wVUxLSqk2XJgDXDTA0qD9Z6nuTvGIEfiMiazsTiSuVVRbs/9Zd1dSbwItd2M/AzgEcQAKYNsKDh5rDthGZlXNXebqB4oKg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706042805; c=relaxed/simple; bh=/siMzgg730XAaeYXsCXHrMecgYnRBP6lXnboSNsLx7Q=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Sz2exj5MBl1NrjAzW1xKfHNb7/iOH4uo2gU0OOPddJrbPsCkoIYX6DbzKV0SOZ2+FDjFEFCywjhfONDc6flFpfYFt7GIlxOKPfDb8jsYHeN32RadCkn2FBq8OnJb/P5WyPEtxwNBH2ftzIQV/+0H0uuP2EFWfyoLlseJcj13SOg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=lneuehyg; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="lneuehyg" Received: from [IPV6:2601:646:8002:4640:7285:c2ff:fefb:fd4] ([IPv6:2601:646:8002:4640:7285:c2ff:fefb:fd4]) (authenticated bits=0) by mail.zytor.com (8.17.2/8.17.1) with ESMTPSA id 40NKisK13270814 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Tue, 23 Jan 2024 12:46:31 -0800 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 40NKisK13270814 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2024011201; t=1706042792; bh=/Do7T71jDeEcLPlXpcSZGgDgkNuz8eJvU6jsgDH4jKw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=lneuehygclfQdCTGTEs6UAwc4ohk20NfA61aHLc1JJEerqhPcYiJBYSkdOrHtZ3j1 4G949XUtlk+C3/2djH43UCAq3OWbxpCd4o0AGdn3CymLHbBu9207PkVetRt7g+UlKh XIU67Nsi0tYocKXEagzTriOMiGQxjjRWr3d6r2FbBXl/0i66i299B+opPtxVebaGq1 plHL2H1OU5zFN1/5Nm0PG0/3LDXqeCgq/PRRJgfq4zKfqr8IN4ZGMtdhwn2UV1LmMN YbfLgvthehLopfgM1Rcq9KRvL3/hqjxnHVU13jhtf2WE7ypGs+bVrF2ZeG2/Nt9ajT +O/fsxJyQqziQ== Message-ID: <4b99bc44-0222-4960-ba1b-97109c80d1e0@zytor.com> Date: Tue, 23 Jan 2024 12:46:31 -0800 Precedence: bulk X-Mailing-List: linux-toolchains@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: A few proposals from the C standards committee Content-Language: en-US To: Linus Torvalds , Jakub Jelinek Cc: paulmck@kernel.org, linux-toolchains@vger.kernel.org, peterz@infradead.org, rostedt@goodmis.org, gregkh@linuxfoundation.org, keescook@chromium.org References: <9162660e-2d6b-47a3-bfa2-77bfc55c817b@paulmck-laptop> <70fd47bb-1539-4301-9cd0-1b94aa066205@paulmck-laptop> From: "H. Peter Anvin" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/23/24 12:43, Linus Torvalds wrote: > On Tue, 23 Jan 2024 at 12:36, Jakub Jelinek wrote: >> >> C++23 has [[assume (condition)]]; for this (see https://wg21.link/p1774r8) >> and GCC supports it also as [[gnu::assume (condition)]] and >> __attribute__((assume (condition)));, both in C (the former only in C23) >> and C++. Side-effects in condition aren't evaluated, so it has >> different behavior from if (!(condition)) __builtin_unreachable (); > > That's lovely, and exactly the kind of thing I'd think is the rigth model. > > If you can also do it in a function declaration, so that it informs > the caller, it's basically perfect. > > IOW, something like > > size_t strlen(const char *s [[assume(s)]]); > > would be the equivalent of "const char *_Nonnull s" in that callers > could warn if not true. > > Except it also would work for other things, not just NULL pointers. > This would *definitely* be frakking nice. -hpa