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: 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, this time from the C++ standards committee
Date: Wed, 5 Jun 2024 12:12:07 -0700	[thread overview]
Message-ID: <168a4d68-256e-45ea-b65f-06ed59f02e31@paulmck-laptop> (raw)
In-Reply-To: <CAHk-=wh921g_+TJ33JRxRGFM2uruMdqG-SONfFOD9UOsLQJ_uw@mail.gmail.com>

On Wed, Jun 05, 2024 at 11:08:40AM -0700, Linus Torvalds wrote:
> On Wed, 5 Jun 2024 at 06:52, Paul E. McKenney <paulmck@kernel.org> wrote:
> >
> > n3243 A Memory model with Synchronization based type aliasing V1,
> >         Eskil Steenberg Hald
> >         https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3243.pdf
> 
> I love the part that admits that the type-based aliasing is broken.
> 
> I don't think the "cast-based barriers" are a sufficient improvement.
> 
> Note the "sufficient". I do think a cast-based barrier would have been
> a huge improvement *originally*, in that it would avoid two absolutely
> huge issues:
> 
>  - "char *" being special
> 
>  - the insane model of "use a union to tell the compiler type-base
> aliasing can happen"
> 
> Both of the above things are disgusting and wrong, but they are mostly
> disgusting and wrong simply because type-based aliasing is entirely
> and utterly wrong to begin with.
> 
> Saying "pointer casts are an aliasing barrier" is a much better and
> more logical model for the type-based thing. No question about that.
> They help make the insanity that is type-based aliasing much more
> manageable.
> 
> However, I don't see that it would be sufficient for us to ever stop
> using the "-fno-strict-aliasing" thing. Because type-based aliasing
> continues to be insane, and even with pointer casting acting as a
> barrier, has real problems.
> 
> The paper points out one such problem: the cast may have been done
> long long before the accesses are done. In fact, unions continue to be
> one very real case of such a situation, where the pointer cast
> basically comes from the type system itself.
> 
> But even with explicit casts, those casts may very naturally be before
> the accesses (the examples in the paper are simplistic, but we have
> the "prepare casts" pattern in the kernel in places like this:
> 
>   static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
>                 struct file *filp)
>   {
>         void __user *argp = (void __user *)arg;
>         int argi = (int)arg;
>         ...
> 
> which admittedly isn't about two pointers that can alias, but is very
> much an example of "it's more convenient to 'prep' the casts before
> use", when the 'arg' argument is then used in multiple different ways
> - sometimes as a pointer, sometimes as an integer, and sometimes as
> the original 'unsigned long'.
> 
> I personally think that the whole type-based aliasing is fundamentally
> unfixable, and that the C standards committee should just admit that.
> It doesn't even *work*, because often the types are the same anyway,
> even when you really really want to say "these accesses can't alias".

All good points!

> The whole type-based aliasing is literally designed for - and by - HPC
> people who (a) had no taste, (b) didn't understand language design and
> just hacked sh*t together and (c) were working with clearly distinct
> types because their workloads are trivial.

To your point, my feeling back in the day was that all of this was
designed to allow FORTRAN programs to be more easily ported to C and C++.

> The HPC people literally tried to solve the issue of "counters are
> integers, but our data is FP, and the two have obviously different
> types, so let's use that information for alias analysis".
> 
> Anybody who doesn't understand how broken and hacky that is SHOULD NOT
> BE ON A LANGUAGE COMMITTEE.
> 
> Seriously. I think it should be a fundamental filter for any C
> language committee member: "Do you think type-based aliasing makes
> sense?". If you get anything but an immediate "No!",  you pull the
> lever that opens the trap-door to the crocodile-infested waters below.
> 
> Or sharks. Sharks are good too.

;-) ;-) ;-)

> And no, "restrict" isn't great, but at least it's a better concept.
> 
> I would suggest that people look at improving 'restrict' and making it
> more useful, and just admit that the type-based thing was a mistake.

One of the complaints was that people don't use "restrict" often enough
to allow all the optimizations that compiler writers would like to do.
Fortunately, there seems to be increasing levels of understanding that
the generated code needs to do something useful.  Here is hoping, anyway!

							Thanx, Paul

      parent reply	other threads:[~2024-06-05 19:12 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-17  9:14 A few proposals, this time from the C++ standards committee Paul E. McKenney
2024-03-17 18:50 ` Linus Torvalds
2024-03-17 20:56   ` Paul E. McKenney
2024-03-17 20:50 ` Linus Torvalds
2024-03-17 21:04   ` Paul E. McKenney
2024-03-17 21:44   ` Linus Torvalds
2024-03-17 22:02     ` Paul E. McKenney
2024-03-17 22:34       ` Linus Torvalds
2024-03-17 23:46         ` Jonathan Martin
2024-03-18  0:42         ` Paul E. McKenney
2024-03-18  1:49           ` Linus Torvalds
2024-03-18  2:44             ` Paul E. McKenney
2024-03-18  2:57               ` Randy Dunlap
2024-03-18  4:42                 ` Paul E. McKenney
2024-03-18  4:45                   ` Randy Dunlap
2024-03-18 16:32   ` Linus Torvalds
2024-03-18 16:48     ` H. Peter Anvin
2024-03-19  7:41 ` Marco Elver
2024-03-19  8:07   ` Jakub Jelinek
2024-06-05 13:52 ` Paul E. McKenney
2024-06-05 18:08   ` Linus Torvalds
2024-06-05 18:24     ` Linus Torvalds
2024-06-05 19:16       ` Paul E. McKenney
2024-06-05 19:12     ` Paul E. McKenney [this message]

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=168a4d68-256e-45ea-b65f-06ed59f02e31@paulmck-laptop \
    --to=paulmck@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.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).