linux-toolchains.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jakub Jelinek <jakub@redhat.com>,
	linux-toolchains@vger.kernel.org, peterz@infradead.org,
	hpa@zytor.com, rostedt@goodmis.org, gregkh@linuxfoundation.org,
	keescook@chromium.org
Subject: Re: A few proposals from the C standards committee
Date: Thu, 25 Jan 2024 05:00:45 -0800	[thread overview]
Message-ID: <af077e30-cd0e-4c16-8664-901319c33190@paulmck-laptop> (raw)
In-Reply-To: <CAHk-=whyh6xxhgZF5ZLH=vT4iE_5joUQX3s6aN5JiF+8NRPr=w@mail.gmail.com>

On Tue, Jan 23, 2024 at 12:43:02PM -0800, Linus Torvalds wrote:
> On Tue, 23 Jan 2024 at 12:36, Jakub Jelinek <jakub@redhat.com> 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.

None of the current compilers support this, but it should not be
hard to mechanically transform this to the form using static inlines,
presumably with a made-up name for one level or the other </handwaving>.
(Especially easy for all concerned if someone other than me does it,
of course...)

However, the possibility of pointers to these functions means that I must
ask if this assume() is part of the type.  There are a lot of reasons
to *not* want it to be part of the type, but that would mean that calls
through pointers would ignore that assume().

Thoughts?

							Thanx, Paul

  parent reply	other threads:[~2024-01-25 13:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-23 16:46 A few proposals from the C standards committee Paul E. McKenney
2024-01-23 18:58 ` Linus Torvalds
2024-01-23 20:00   ` Paul E. McKenney
2024-01-23 20:20     ` Linus Torvalds
2024-01-23 20:35       ` Jakub Jelinek
2024-01-23 20:43         ` Linus Torvalds
2024-01-23 20:46           ` H. Peter Anvin
2024-01-24 13:46             ` Paul E. McKenney
2024-01-25 13:00           ` Paul E. McKenney [this message]
2024-01-24 13:16         ` Paul E. McKenney
2024-01-23 20:44       ` H. Peter Anvin
2024-01-24 12:52       ` Paul E. McKenney
2024-01-23 20:39     ` Linus Torvalds
2024-01-23 22:35   ` Martin Uecker
2024-01-23 20:16 ` H. Peter Anvin
2024-01-23 20:24   ` Linus Torvalds
2024-01-24 14:58     ` Paul E. McKenney
2024-01-25 12:52   ` Paul E. McKenney
2024-01-23 22:39 ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=af077e30-cd0e-4c16-8664-901319c33190@paulmck-laptop \
    --to=paulmck@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=jakub@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).