public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@transmeta.com>
To: Jamie Lokier <egcs@tantalophile.demon.co.uk>
Cc: Toon Moene <toon@moene.indiv.nluug.nl>, Andi Kleen <ak@muc.de>,
	law@cygnus.com, Joe Buck <jbuck@Synopsys.COM>,
	craig@jcb-sc.com, mark@codesourcery.com, davem@redhat.com,
	chip@perlsupport.com, egcs@egcs.cygnus.com
Subject: Re: Linux and aliasing?
Date: Sat, 05 Jun 1999 19:35:00 -0000	[thread overview]
Message-ID: <Pine.LNX.3.95.990605190423.14928G-100000@penguin.transmeta.com> (raw)
In-Reply-To: <19990605222555.B15508@pcep-jamie.cern.ch>

On Sat, 5 Jun 1999, Jamie Lokier wrote:
> Jamie's suggestion de jour.

I like your suggestion - it dos sound like a lot more work especially for
the compiler than my simplistic one, but the fact that we would at least
get warnings from the compiler about them means that we wouldn't have to
rely on somebody going through 30MB worth of sources by hand..

>   Linus wants non-union (ie. non-ugly) casts to do the sensible thing.
>   What that is isn't quite clear -- after thinking it through.
>   If it's just aesthetics, I don't see why a macro wouldn't do ;-)

A macro can do the same thing (the same way I think the current gcc lvalue
cast could be done with a macro), but my approach has the in my opinion
very useful behaviour that it makes most "normal" type cast problems just
automatically do the right thing. So in many cases it would work as-is
(not just for kernel code), and in cases where it does not (ie the cast is
non-local) my proposal has a way out (add another cast that _is_ local
to the actual de-reference).

I don't really see why people hate the proposal so much, but maybe that's
just my personal coding style. I do not consider pointer casts (or any
other kinds of casts) acceptable programming practice for any normal
cases, so just about =all= the casts I ever see are of the type where
alias information should obviously be disabled. So to me it sounds like a
"natural" way of doing things.

(Just to clarify - it's not as if the linux kernel does a _lot_ of ugly
pointer stuff. It's just that it does happen, and it isn't done in one one
well-defined area or similar.)

It seems that other people use more casts for "normal" things, and are
actually afraid of my proposal for performance reasons. I'm surprised:
people that do things like that are usually not the people who complain
about others coding standards ;)

Anyway, I grepped the kernel for "likely" places where my change would
make a difference by using the following heuristic grep:

	grep '\*(.*\* *)' */*.c

and in basically all cases the compiler would have done the right thing if
it had followed my proposal.

THAT is why I like it. It does the RightThing(tm), with basically zero
complexity for either the user or the compiler. It is a "do what I mean" 
kind of patch. 

"Do what I mean" is a quality of implementation thing. Yes, all of this is
obviously not defined by the standard. But exactly because it is NOT
defined by the standard, it's very good if the behaviour is what you'd
expect.

The people who worry about the thing being a performance problem for them:
try the above grep and see what it shows you. No, the grep doesn't really
catch all the cases that the compiler change would impact, but it should
give you a rough idea.

In particular, if the grep comes up empty (ie "Well written code without
any strange casts"), you probably wouldn't actually be impacted by the
"Linus proposal" at all. 

>   In particlar, a cast may be conforming, in which case the compiler
>   should strive the generate the best allowed code (unless it's
>   pathological).

"may be conforming", yes. Are there any real life cases where it really
matters? The case where my rule kicks in is definitely "suspicious" - I
agree that it _may_ conform, but do people actually ever write code like
that in strictly conforming programs? That's why I'd like to see what the
grep above shows people..

>   Issues raised: 
> 
>   - Lots of legacy code uses casts, assuming nothing weird will happen.
>   - Weird things now happen.

Right. The "Linus proposal" would not make that go away completely, but it
would make a large percentage of the weird cases do what the old code
expected.

>   - "non-conforming cast implies pointer may alias all" + "full flow
>     analysis" got proposed.  No one likes it.  Bin.

Yes.

>   - "non-... all" + "*no* flow analysis" got proposed by Linus.  It's a
>     simple special case, arguably syntactic.  But it has semantic warts:
>        *(foo_t*) &bar = foo; 
>     now means something different than:
>        { foo_t* p = (foo_t*) &bar; *p = foo; }

I understand that people can see this as a wart, but if you consider it
syntactic then you shouldn't even _expect_ the above to be the same thing.

In fact, I'd like to consider it a bonus that you will =not= get the
looser alias semantics for the case where you actually assign the pointer.
So you can use the second version as a way to _avoid_ the "Linus rule" if
you like it in general but in a specific case want to disable it.

I guess I'm not convincing you.

>   - "type attribute" got proposed by Linus too.  This I like.

Well, that one is just the "implementation part" of my basic proposal.

It can be done on its own without the "implied no-alias" of course. But I
_meant_ it to be done in conjunction with my other proposal, just
explaining how it would be implemented.

> Jamie's thought of the day
> --------------------------

[ deleted ]

Hey, works for me. It seems to do the Linus proposal in a "warning sense",
if I understood you correctly, with a way to just force whichever actual
semantics you want. Right?

		Linus

WARNING: multiple messages have this Message-ID
From: Linus Torvalds <torvalds@transmeta.com>
To: Jamie Lokier <egcs@tantalophile.demon.co.uk>
Cc: Toon Moene <toon@moene.indiv.nluug.nl>, Andi Kleen <ak@muc.de>,
	law@cygnus.com, Joe Buck <jbuck@Synopsys.COM>,
	craig@jcb-sc.com, mark@codesourcery.com, davem@redhat.com,
	chip@perlsupport.com, egcs@egcs.cygnus.com
Subject: Re: Linux and aliasing?
Date: Wed, 30 Jun 1999 15:43:00 -0000	[thread overview]
Message-ID: <Pine.LNX.3.95.990605190423.14928G-100000@penguin.transmeta.com> (raw)
Message-ID: <19990630154300.JSRQNrQVg2qu1G9VumcWnRHzjszPK-bgAfKy5ETNq0c@z> (raw)
In-Reply-To: <19990605222555.B15508@pcep-jamie.cern.ch>

On Sat, 5 Jun 1999, Jamie Lokier wrote:
> Jamie's suggestion de jour.

I like your suggestion - it dos sound like a lot more work especially for
the compiler than my simplistic one, but the fact that we would at least
get warnings from the compiler about them means that we wouldn't have to
rely on somebody going through 30MB worth of sources by hand..

>   Linus wants non-union (ie. non-ugly) casts to do the sensible thing.
>   What that is isn't quite clear -- after thinking it through.
>   If it's just aesthetics, I don't see why a macro wouldn't do ;-)

A macro can do the same thing (the same way I think the current gcc lvalue
cast could be done with a macro), but my approach has the in my opinion
very useful behaviour that it makes most "normal" type cast problems just
automatically do the right thing. So in many cases it would work as-is
(not just for kernel code), and in cases where it does not (ie the cast is
non-local) my proposal has a way out (add another cast that _is_ local
to the actual de-reference).

I don't really see why people hate the proposal so much, but maybe that's
just my personal coding style. I do not consider pointer casts (or any
other kinds of casts) acceptable programming practice for any normal
cases, so just about =all= the casts I ever see are of the type where
alias information should obviously be disabled. So to me it sounds like a
"natural" way of doing things.

(Just to clarify - it's not as if the linux kernel does a _lot_ of ugly
pointer stuff. It's just that it does happen, and it isn't done in one one
well-defined area or similar.)

It seems that other people use more casts for "normal" things, and are
actually afraid of my proposal for performance reasons. I'm surprised:
people that do things like that are usually not the people who complain
about others coding standards ;)

Anyway, I grepped the kernel for "likely" places where my change would
make a difference by using the following heuristic grep:

	grep '\*(.*\* *)' */*.c

and in basically all cases the compiler would have done the right thing if
it had followed my proposal.

THAT is why I like it. It does the RightThing(tm), with basically zero
complexity for either the user or the compiler. It is a "do what I mean" 
kind of patch. 

"Do what I mean" is a quality of implementation thing. Yes, all of this is
obviously not defined by the standard. But exactly because it is NOT
defined by the standard, it's very good if the behaviour is what you'd
expect.

The people who worry about the thing being a performance problem for them:
try the above grep and see what it shows you. No, the grep doesn't really
catch all the cases that the compiler change would impact, but it should
give you a rough idea.

In particular, if the grep comes up empty (ie "Well written code without
any strange casts"), you probably wouldn't actually be impacted by the
"Linus proposal" at all. 

>   In particlar, a cast may be conforming, in which case the compiler
>   should strive the generate the best allowed code (unless it's
>   pathological).

"may be conforming", yes. Are there any real life cases where it really
matters? The case where my rule kicks in is definitely "suspicious" - I
agree that it _may_ conform, but do people actually ever write code like
that in strictly conforming programs? That's why I'd like to see what the
grep above shows people..

>   Issues raised: 
> 
>   - Lots of legacy code uses casts, assuming nothing weird will happen.
>   - Weird things now happen.

Right. The "Linus proposal" would not make that go away completely, but it
would make a large percentage of the weird cases do what the old code
expected.

>   - "non-conforming cast implies pointer may alias all" + "full flow
>     analysis" got proposed.  No one likes it.  Bin.

Yes.

>   - "non-... all" + "*no* flow analysis" got proposed by Linus.  It's a
>     simple special case, arguably syntactic.  But it has semantic warts:
>        *(foo_t*) &bar = foo; 
>     now means something different than:
>        { foo_t* p = (foo_t*) &bar; *p = foo; }

I understand that people can see this as a wart, but if you consider it
syntactic then you shouldn't even _expect_ the above to be the same thing.

In fact, I'd like to consider it a bonus that you will =not= get the
looser alias semantics for the case where you actually assign the pointer.
So you can use the second version as a way to _avoid_ the "Linus rule" if
you like it in general but in a specific case want to disable it.

I guess I'm not convincing you.

>   - "type attribute" got proposed by Linus too.  This I like.

Well, that one is just the "implementation part" of my basic proposal.

It can be done on its own without the "implied no-alias" of course. But I
_meant_ it to be done in conjunction with my other proposal, just
explaining how it would be implemented.

> Jamie's thought of the day
> --------------------------

[ deleted ]

Hey, works for me. It seems to do the Linus proposal in a "warning sense",
if I understood you correctly, with a way to just force whichever actual
semantics you want. Right?

		Linus

  reply	other threads:[~1999-06-05 19:35 UTC|newest]

Thread overview: 218+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-03 10:23 Chip Salzenberg
1999-06-03 10:37 ` mark
1999-06-03 11:26   ` David S. Miller
1999-06-03 12:03     ` mark
1999-06-03 12:25       ` David S. Miller
1999-06-03 20:06         ` craig
1999-06-03 23:03           ` Linus Torvalds
1999-06-03 23:45             ` mark
1999-06-04  0:04               ` Linus Torvalds
1999-06-04  1:08                 ` Branko Cibej
1999-06-30 15:43                   ` Branko Cibej
1999-06-04  1:24                 ` Joe Buck
1999-06-04  1:50                   ` Linus Torvalds
1999-06-04  5:46                     ` craig
1999-06-04  7:22                       ` burley (was Re: Linux and aliasing?) Mark Hahn
1999-06-04  8:16                         ` craig
1999-06-30 15:43                           ` craig
1999-06-30 15:43                         ` Mark Hahn
1999-06-04  8:35                       ` Linux and aliasing? Linus Torvalds
1999-06-04 10:04                         ` Joe Buck
1999-06-04 10:22                           ` Jeffrey A Law
1999-06-04 10:31                             ` Joe Buck
1999-06-04 10:53                               ` Jeffrey A Law
1999-06-30 15:43                                 ` Jeffrey A Law
1999-06-30 15:43                               ` Joe Buck
1999-07-11 10:55                               ` Jeffrey A Law
1999-07-31 23:33                                 ` Jeffrey A Law
1999-06-04 11:11                             ` Toon Moene
1999-06-04 12:20                               ` Jeffrey A Law
1999-06-05  5:45                                 ` Toon Moene
1999-06-05  6:23                                   ` Andi Kleen
1999-06-05 10:32                                     ` Toon Moene
1999-06-05 13:26                                       ` Jamie Lokier
1999-06-05 19:35                                         ` Linus Torvalds [this message]
1999-06-06  1:18                                           ` Martin v. Loewis
1999-06-06 10:46                                             ` Linus Torvalds
1999-06-30 15:43                                               ` Linus Torvalds
1999-06-06 17:56                                             ` Jason Merrill
1999-06-06 19:24                                               ` Tim Hollebeek
1999-06-30 15:43                                                 ` Tim Hollebeek
1999-06-06 22:23                                               ` Jeffrey A Law
1999-06-30 15:43                                                 ` Jeffrey A Law
     [not found]                                               ` <199906070645.IAA00615@mira.isdn.cs.tu-berlin.de>
1999-06-07  2:14                                                 ` Jason Merrill
1999-06-07  8:02                                                   ` mark
1999-06-07  8:41                                                     ` David S. Miller
1999-06-07  9:24                                                       ` Jeffrey A Law
1999-06-07  9:29                                                         ` David S. Miller
1999-06-30 15:43                                                           ` David S. Miller
1999-06-30 15:43                                                         ` Jeffrey A Law
1999-06-07  9:32                                                       ` Joe Buck
1999-06-30 15:43                                                         ` Joe Buck
1999-06-30 15:43                                                       ` David S. Miller
1999-06-30 15:43                                                     ` mark
1999-06-07 13:11                                                   ` Jeffrey A Law
1999-06-30 15:43                                                     ` Jeffrey A Law
1999-06-30 15:43                                                   ` Jason Merrill
1999-06-30 15:43                                               ` Jason Merrill
1999-06-30 15:43                                             ` Martin v. Loewis
1999-06-30 15:43                                           ` Linus Torvalds
1999-06-30 15:43                                         ` Jamie Lokier
1999-06-05 18:48                                       ` Linus Torvalds
1999-06-30 15:43                                         ` Linus Torvalds
1999-06-30 15:43                                       ` Toon Moene
1999-06-05 10:37                                     ` mark
1999-06-05 11:09                                       ` David S. Miller
1999-06-05 12:11                                         ` Toon Moene
1999-06-05 12:21                                           ` David S. Miller
1999-06-05 16:51                                             ` mark
1999-06-30 15:43                                               ` mark
1999-06-30 15:43                                             ` David S. Miller
1999-06-30 15:43                                           ` Toon Moene
1999-06-07  6:01                                         ` Joern Rennecke
1999-06-30 15:43                                           ` Joern Rennecke
1999-06-30 15:43                                         ` David S. Miller
1999-06-05 11:35                                       ` Andi Kleen
1999-06-30 15:43                                         ` Andi Kleen
1999-06-05 12:41                                       ` Jamie Lokier
1999-06-05 14:43                                         ` Martin v. Loewis
1999-06-30 15:43                                           ` Martin v. Loewis
1999-06-05 16:53                                         ` mark
1999-06-07  2:36                                           ` Jamie Lokier
1999-06-07  8:04                                             ` mark
1999-06-30 15:43                                               ` mark
1999-06-30 15:43                                             ` Jamie Lokier
1999-06-30 15:43                                           ` mark
1999-06-30 15:43                                         ` Jamie Lokier
1999-06-30 15:43                                       ` mark
1999-06-30 15:43                                     ` Andi Kleen
1999-06-06 23:12                                   ` f77 vs type based alias analysis Jeffrey A Law
1999-06-30 15:43                                     ` Jeffrey A Law
1999-06-06 23:20                                   ` Linux and aliasing? Jeffrey A Law
1999-06-30 15:43                                     ` Jeffrey A Law
1999-06-30 15:43                                   ` Toon Moene
1999-06-30 15:43                                 ` Jeffrey A Law
1999-06-05  4:05                               ` Andi Kleen
1999-06-30 15:43                                 ` Andi Kleen
1999-06-30 15:43                               ` Toon Moene
1999-06-30 15:43                             ` Jeffrey A Law
1999-06-04 11:49                           ` Linus Torvalds
1999-06-04 13:03                             ` Gabriel Dos_Reis
1999-06-04 13:13                               ` Joe Buck
1999-06-30 15:43                                 ` Joe Buck
1999-06-30 15:43                               ` Gabriel Dos_Reis
1999-06-30 15:43                             ` Linus Torvalds
1999-06-04 12:59                           ` Alexandre Oliva
1999-06-04 13:29                             ` Joe Buck
1999-06-04 13:39                               ` Alexandre Oliva
1999-06-30 15:43                                 ` Alexandre Oliva
1999-06-30 15:43                               ` Joe Buck
1999-06-30 15:43                             ` Alexandre Oliva
1999-06-30 15:43                           ` Joe Buck
1999-06-30 15:43                         ` Linus Torvalds
1999-06-30 15:43                       ` craig
1999-06-30 15:43                     ` Linus Torvalds
1999-06-30 15:43                   ` Joe Buck
1999-06-04  5:47                 ` craig
1999-06-30 15:43                   ` craig
1999-06-04  7:11                 ` mark
1999-06-04  8:38                   ` Linus Torvalds
1999-06-30 15:43                     ` Linus Torvalds
1999-06-30 15:43                   ` mark
1999-06-04  8:41                 ` Tim Hollebeek
1999-06-04  8:53                   ` Jeffrey A Law
1999-06-30 15:43                     ` Jeffrey A Law
1999-06-30 15:43                   ` Tim Hollebeek
1999-06-30 15:43                 ` Linus Torvalds
1999-06-30 15:43               ` mark
1999-06-04  5:47             ` craig
1999-06-04  8:17               ` Linus Torvalds
1999-06-04  8:49                 ` craig
1999-06-04  8:57                   ` Linus Torvalds
1999-06-04  9:02                     ` Jean-Pierre Radley
1999-06-30 15:43                       ` Jean-Pierre Radley
1999-06-30 15:43                     ` Linus Torvalds
1999-06-30 15:43                   ` craig
1999-06-30 15:43                 ` Linus Torvalds
1999-06-30 15:43               ` craig
1999-06-04  8:39             ` Tim Hollebeek
1999-06-04  8:55               ` Linus Torvalds
1999-06-04 15:20                 ` Richard Henderson
1999-06-05  9:50                   ` Linus Torvalds
1999-06-05 11:00                     ` mark
1999-06-06 10:30                       ` Linus Torvalds
1999-06-06 10:44                         ` mark
1999-06-06 14:17                           ` Linus Torvalds
1999-06-06 17:41                             ` mark
1999-06-07  8:58                               ` Linus Torvalds
1999-06-07  9:18                                 ` mark
1999-06-07  9:29                                   ` Linus Torvalds
1999-06-07  9:38                                     ` Tim Hollebeek
1999-06-07 10:05                                       ` Jamie Lokier
1999-06-30 15:43                                         ` Jamie Lokier
1999-06-07 10:44                                       ` Linus Torvalds
1999-06-07 11:22                                         ` Jeffrey A Law
1999-06-08  1:34                                           ` Nick Ing-Simmons
1999-06-08  1:48                                             ` Jeffrey A Law
1999-06-30 15:43                                               ` Jeffrey A Law
1999-06-30 15:43                                             ` Nick Ing-Simmons
1999-06-30 15:43                                           ` Jeffrey A Law
1999-06-30 15:43                                         ` Linus Torvalds
1999-06-30 15:43                                       ` Tim Hollebeek
1999-06-30 15:43                                     ` Linus Torvalds
1999-06-30 15:43                                   ` mark
1999-06-07 13:34                                 ` Jamie Lokier
1999-06-30 15:43                                   ` Jamie Lokier
1999-06-30 15:43                                 ` Linus Torvalds
1999-06-30 15:43                               ` mark
1999-06-30 15:43                             ` Linus Torvalds
1999-06-30 15:43                           ` mark
1999-06-30 15:43                         ` Linus Torvalds
1999-06-30 15:43                       ` mark
1999-06-30 15:43                     ` Linus Torvalds
1999-06-30 15:43                   ` Richard Henderson
1999-06-30 15:43                 ` Linus Torvalds
1999-06-30 15:43               ` Tim Hollebeek
1999-06-04 15:02             ` Richard Henderson
1999-06-04 16:50               ` Bernd Schmidt
1999-06-30 15:43                 ` Bernd Schmidt
1999-06-05  9:35               ` Linus Torvalds
1999-06-05 13:34                 ` Richard Henderson
1999-06-05 18:40                   ` Linus Torvalds
1999-06-30 15:43                     ` Linus Torvalds
1999-06-05 21:38                   ` Jakub Jelinek
1999-06-30 15:43                     ` Jakub Jelinek
1999-06-30 15:43                   ` Richard Henderson
1999-06-30 15:43                 ` Linus Torvalds
1999-06-30 15:43               ` Richard Henderson
1999-06-30 15:43             ` Linus Torvalds
1999-06-03 23:53           ` Martin v. Loewis
1999-06-30 15:43             ` Martin v. Loewis
     [not found]           ` <v04205101b37d700fbf8d@[192.168.1.254]>
1999-06-04  7:01             ` craig
1999-06-30 15:43               ` craig
1999-06-30 15:43           ` craig
1999-06-30 15:43         ` David S. Miller
1999-06-03 13:31       ` Andi Kleen
1999-06-30 15:43         ` Andi Kleen
1999-06-30 15:43       ` mark
1999-06-30 15:43     ` David S. Miller
1999-06-03 12:02   ` Andi Kleen
1999-06-03 15:38     ` Martin v. Loewis
1999-06-30 15:43       ` Martin v. Loewis
1999-06-30 15:43     ` Andi Kleen
1999-06-30 15:43   ` mark
1999-06-30 15:43 ` Chip Salzenberg
1999-06-04 11:54 Mike Stump
1999-06-04 12:13 ` Jeffrey A Law
1999-06-04 13:25   ` Sylvain Pion
1999-06-04 13:32     ` Jeffrey A Law
1999-06-30 15:43       ` Jeffrey A Law
1999-06-30 15:43     ` Sylvain Pion
1999-06-30 15:43   ` Jeffrey A Law
1999-06-30 15:43 ` Mike Stump
1999-06-06 15:08 Ross Harvey
1999-06-06 15:46 ` Linus Torvalds
1999-06-30 15:43   ` Linus Torvalds
1999-06-06 17:29 ` David S. Miller
1999-06-30 15:43   ` David S. Miller
1999-06-30 15:43 ` Ross Harvey

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=Pine.LNX.3.95.990605190423.14928G-100000@penguin.transmeta.com \
    --to=torvalds@transmeta.com \
    --cc=ak@muc.de \
    --cc=chip@perlsupport.com \
    --cc=craig@jcb-sc.com \
    --cc=davem@redhat.com \
    --cc=egcs@egcs.cygnus.com \
    --cc=egcs@tantalophile.demon.co.uk \
    --cc=jbuck@Synopsys.COM \
    --cc=law@cygnus.com \
    --cc=mark@codesourcery.com \
    --cc=toon@moene.indiv.nluug.nl \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).