From: Linus Torvalds <torvalds@linux-foundation.org>
To: paulmck@kernel.org
Cc: 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: Tue, 23 Jan 2024 12:20:14 -0800 [thread overview]
Message-ID: <CAHk-=wgykfH7dP3rYmrBuVu0qbdFu37eKyyBrdzcshUZErPj-g@mail.gmail.com> (raw)
In-Reply-To: <70fd47bb-1539-4301-9cd0-1b94aa066205@paulmck-laptop>
On Tue, 23 Jan 2024 at 12:00, Paul E. McKenney <paulmck@kernel.org> wrote:
>
> Would you be OK with something that required a new variable for the
> pointer that was now known not to be NULL? (My guess is "no", given the
> following discussion on value ranges, but I figured that I should ask.)
Yeah, no, I think that ends up putting the burden on the programmer in
the form of a very cumbersome syntax, and just more room for mistakes.
> In some implementations, you can use assertions to get at least part
> of this effect:
Yes. However, the problem with that is that the assert generally then
comes with extra code generation.
IOW, a plain
_Nonnull p;
in my opinion should imply a promise by the developer - and then you
could have some "debug build" model where the compiler then verifies
the promises.
But an
assert(p);
implies more than a promise by the developer - it implies that the
compiler *should* generate some code to verify.
And yes, obviously assert() comes with the traditional NDEBUG flag,
but that one has the historical baggage of causing the assert() to be
a no-op. IOW, you lose the code generation, but you also lose the
promise from the developer.
Could all of this be done *properly*? Yes. And I think it should. But
properly literally means having good documented "this is what this
means".
And no, __builtin_unreachable() is not it either, because it again has
the same issue as "assert()" - in *practice* compilers can use it as a
hint, but that's an incidental result, not part of a documented "this
is how you specify a known range"
So yes, I can do things like
if (a < 0) __builtin_unreachable();
and it will generate the *code* that I want, but it sure as hell isn't
some standard C syntax.
Linus
next prev parent reply other threads:[~2024-01-23 20:20 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 [this message]
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
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='CAHk-=wgykfH7dP3rYmrBuVu0qbdFu37eKyyBrdzcshUZErPj-g@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=linux-toolchains@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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).