public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@codesourcery.com>
To: Ziemowit Laski <zlaski@apple.com>
Cc: Steve Naroff <snaroff@apple.com>,
	gcc mailing list <gcc@gcc.gnu.org>,
	 Matt Austern <austern@apple.com>, Michael Matz <matz@suse.de>,
	Joe Buck <Joe.Buck@synopsys.com>,
	 Andrew Pinski <pinskia@physics.uc.edu>,
	Mike Stump <mrs@apple.com>
Subject: Re: generalized lvalues -- patch outline
Date: Tue, 23 Nov 2004 22:24:00 -0000	[thread overview]
Message-ID: <41A3B637.9030706@codesourcery.com> (raw)
In-Reply-To: <EA8B9D62-3D93-11D9-91AF-000D9330C50E@apple.com>

Ziemowit Laski wrote:

> By "inducing a type conversion", I meant generating code to make the 
> conversion happen, as in '(float)intValue'.  Perhaps I should have said 
> 'non-trivial type conversion' or some such.  In C, conversions among 
> pointer types should always be trivial, but in C++, conversion operators 
> could kick in.  In those non-trivial cases, we would disallow the lvalue 
> cast.

Ok, so whether this extension is applicable is implementation defined,
based on the sizes of the supported data types.  C and C++ standards
do not currently have such conditionally defined behaviour (although there
are moves to define such a term in C++ at least).

>>>   - The lvalue cast is being assigned to, incremented or decremented;
>>
>> ... or modified.  What is the bitrepresentation of the lvalue?  Is it
>> that of the newly specified type, or is the static type of the location?
> 
> 
> Since we're talking about pointers, the bit representation does not 
> change.

This is an implementation assumption.  Some machines have different
bit representations for char * and int * pointers for instance (do
we support them, I don't know).  So, this is another implementation
restriction.

>  Microsoft also allows lvalue casts so long as the type being 
> cast to is not larger than the original type (e.g., '(short)longValue' 
> is OK whereas '(long)shortValue' is not); in those cases, I'm fairly 
> certain
> we want the bit layout of the newly specified type.

so (short)longValue should not touch longValue's bits outside of a
short?  But I thought you were restricting to casts between object pointer
types, so why is this relevent?

>>>   - The lvalue is of a pointer type, and is being cast to a pointer 
>>> type.
>>
>> ok, so this answers my questions about point 1. Any pointer type? Like
>> the disallowed func->object conversion in C++? What about references
>> and/or references to pointer types?  Does array/function->pointer
>> decay occur? It might make sense to restrict the original lvalue
>> type to 'void *'.
> 
> 
> Just plain C pointers ('foo *', 'bar *'); no references and no 
> pointers-to-members, although I see no reason why we should disallow 
> arrays and function pointers.

so '(foo *)ary' is permitted?

>> Are there any restrictions on the original lvalue that is being cast?

> I don't understand this question -- what kind of restrictions could/should
> there be?

I don't know.  you tell me, you're the one specifying this extension

> 
>> Is this extension composable? For instance what about the following,
>>     #define MAGIC_REGISTER ((void *)p)
>>     (int *)MAGIC_REGISTER += 2
>>
>> What about
>>     (expr, (int *)p) = something
>> in C++?  In C++ operator, is an lvalue if its second operand is an
>> lvalue. Similarly for ?:
> 
> 
> I think the examples you give here should all work.
do you mean that these examples must be accepted by the extension?
AFAICT the first one (int *)(void *)p does not as currently specified,
because (void *)p is not an lvalue cast as it's not being assigned to
or modified. If these are to be accepted, something is lacking in the
specification.

>> Have you thought about specifying this in terms of a rewriting rule?
> 
> 
> Under the conditions specified above,
> 
>          (foo)bar
> 
> could be rewritten to
> 
>          *((foo *)&bar)

this rewriting rule falls foul of the type based aliasing rules.

>> Do you have an analysis of interaction with existing features?
> 
> 
> I don't, although I'm not sure what would constitute "analysis" in this 
> context.

Well, consider all the existing language features and show how they are
either unaffected, or the changes are not detrimental.

> I suppose you can take the rewrite rule above and then try to see if the 
> rewritten expression
> would play nicely as an rvalue in other contexts; off the top of my 
> head, I can't think of
> situations where it would not, though I welcome others to poke holes in 
> this theory.

I showed your rewriting rules break existing optimizations (or other
ways around, existing optimizations will cause your rewriting rule to
generate code that does not do what your extension claims to do). I find
'off the top of my head' to be an unsatisfactory way of defining language
extensions.

> One important thing to note is that the extension I'm proposing does not 
> change existing, valid behavior; it only affects cases that currently 
> (with TOT gcc 4.0) produce hard errors.
> 
>>  What
>> programming errors would fall into this?
> 
> 
> Are you asking, "how are programmers likely to misconstrue what this 
> extension does"?

I am asking what currently rejected programs that *really* are
programming errors, would silently be accepted, and then lead to hard
to debug problems.

> I think most programmers out there would probably be 
> surprised that this is an extension at all, since most would expect 
> something like
> 
>    (foo)bar = value;
> 
> to simply "work" :-); so probably the biggest pitfall would be that, 
> even with the extension enabled, programmers will still get non-lvalue 
> errors sometimes and then wonder why.

I beg to differ.  I have no data on what 'most' C programmers think about
bits of code that are not specified in the C standard, or any book
that teaches standard C or in the gcc documentation.  How have you
determined what 'most' programmers think about this?

>> Why do you want this extension?
>> I see 6 different possible rationales. Are they all applicable?
> 
> 
> Yes, they are all applicable, although any one of them taken separately 
> is sufficient justification, IMO. 



> MS cnd CW compatibility is important 
> because of code that is being brought over, but I don't think we 
> necessarily have to implement each corner case of this extension as 
> supported by these (and other) compilers (we could, but that would go 
> way beyond what we are proposing here).

What code is being brought over?  If compatibility is important, what
are the specifications of MS's and CW's extensions.  It appears this
information is being gathered.  It would be useless to implement a
partial extension, if the main use in the ported code was a different
bit of the extension.


>  Rather, what we are concerned 
> with is how the extensions tend to be used in real code.  And most 
> existing usage, both in Apple's case and in examples cited by Michael 
> Matz, has to do with pointer type manipulation.

 From this I understand that the use in Apple's code is accidental, as
you've not shown the coding guidelines.

You've not followed up on the ObjC rationale.  Is that an issue or
not?

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

  parent reply	other threads:[~2004-11-23 22:14 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-18  3:50 generalized lvalues Matt Austern
2004-11-18  3:52 ` Andrew Pinski
2004-11-18  4:01 ` Andrew Pinski
2004-11-18  4:18   ` Daniel Berlin
2004-11-18  4:21   ` Andrew Pinski
2004-11-18  4:27     ` Matt Austern
2004-11-18  7:15       ` Joe Buck
2004-11-18  7:37         ` Matt Austern
2004-11-18 13:17           ` Giovanni Bajo
2004-11-18 17:57           ` Joe Buck
2004-11-18 18:28         ` Mike Stump
2004-11-18 18:44           ` Joe Buck
2004-11-19  1:39             ` Mike Stump
2004-11-19  4:52               ` Matt Austern
2004-11-19 22:24                 ` Michael Matz
2004-11-19 22:30                   ` Robert McNulty Junior
2004-11-20  1:00                   ` Ziemowit Laski
2004-11-20  1:20                     ` Joe Buck
2004-11-20  1:51                       ` Ziemowit Laski
2004-11-20  5:04                         ` Joe Buck
2004-11-20  5:17                           ` Ziemowit Laski
2004-11-22 20:54                             ` generalized lvalues -- patch outline Ziemowit Laski
2004-11-22 21:01                               ` Andrew Pinski
2004-11-22 21:11                                 ` Ziemowit Laski
2004-11-22 21:39                                 ` Matt Austern
2004-11-22 22:11                                   ` Joe Buck
2004-11-22 22:12                                     ` Matt Austern
2004-11-23  0:06                                       ` Gabriel Dos Reis
2004-11-23  0:04                                   ` Gabriel Dos Reis
2004-11-23  0:27                                     ` Mike Stump
2004-11-24 20:40                                     ` Kai Henningsen
2004-11-23  0:11                                   ` Mark Mitchell
2004-11-23  1:19                                     ` Matt Austern
2004-11-23  1:26                                       ` Mark Mitchell
2004-11-23  1:32                                         ` Dale Johannesen
2004-11-23  1:42                                           ` Mark Mitchell
2004-11-23  1:45                                           ` Andrew Pinski
2004-11-23  1:55                                             ` Dale Johannesen
2004-11-23  1:56                                               ` Andrew Pinski
2004-11-23  2:12                                                 ` Dale Johannesen
2004-11-23  2:10                                               ` Marcus G. Daniels
2004-11-23  9:43                                       ` Eric Botcazou
2004-11-23 18:27                                       ` Aaron W. LaFramboise
2004-11-22 21:23                               ` Nathan Sidwell
2004-11-22 22:33                                 ` Ziemowit Laski
2004-11-23  0:09                                   ` Gabriel Dos Reis
2004-11-23  9:54                                   ` Nathan Sidwell
2004-11-23 13:35                                     ` Michael Matz
2004-11-23 14:56                                       ` Daniel Berlin
2004-11-23 15:02                                         ` Michael Matz
2004-11-23 15:15                                           ` Andrew Pinski
2004-11-23 15:47                                             ` Michael Matz
2004-11-23 15:56                                               ` Gabriel Dos Reis
2004-11-23 15:50                                             ` Steve Naroff
2004-11-23 15:51                                               ` Gabriel Dos Reis
2004-11-23 16:50                                             ` Eric Botcazou
2004-11-23 17:01                                               ` Paul Koning
2004-11-23 17:16                                                 ` Andreas Schwab
2004-11-23 18:03                                                 ` Thomas Kunert
2004-11-23 18:30                                                   ` Nathan Sidwell
2004-11-23 18:57                                                     ` Thomas Kunert
2004-11-23 21:21                                                   ` Paul Koning
2004-11-23 21:52                                                     ` Thomas Kunert
2004-11-23 15:51                                           ` Gabriel Dos Reis
2004-11-23 16:12                                             ` Michael Matz
2004-11-23 16:31                                               ` Richard Guenther
2004-11-23 16:44                                               ` Andreas Schwab
2004-11-23 20:16                                               ` Gabriel Dos Reis
2004-11-23 15:01                                       ` Nathan Sidwell
2004-11-23 15:09                                         ` Michael Matz
2004-11-23 19:11                                         ` Matt Austern
2004-11-23 21:10                                           ` Eric Botcazou
2004-11-23 21:34                                     ` Ziemowit Laski
2004-11-23 22:09                                       ` Joseph S. Myers
2004-11-23 22:23                                         ` Eric Botcazou
2004-11-23 22:27                                           ` Joseph S. Myers
2004-11-24  0:05                                             ` Eric Botcazou
2004-11-24  0:07                                               ` Steven Bosscher
2004-11-24  0:32                                               ` Joseph S. Myers
2004-11-25  8:41                                                 ` Ian Lance Taylor
2004-11-25 20:41                                                   ` Gabriel Dos Reis
2004-11-25 21:54                                                     ` Matt Austern
2004-11-25 23:27                                                       ` Gabriel Dos Reis
2004-11-29 18:06                                                       ` Joe Buck
2004-11-29 18:57                                                         ` Matt Austern
2004-11-23 23:27                                         ` Gabriel Dos Reis
2004-11-23 22:24                                       ` Nathan Sidwell [this message]
2004-11-23  0:07                                 ` Gabriel Dos Reis
2004-11-24 20:43                                   ` Kai Henningsen
2004-11-24 23:09                                     ` Gabriel Dos Reis
2004-11-24 23:17                                       ` Zack Weinberg
2004-11-22 21:31                               ` Richard Henderson
2004-11-23  0:11                                 ` Gabriel Dos Reis
2004-11-23  0:03                               ` Jonathan Lennox
2004-11-20  1:40                     ` generalized lvalues Joseph S. Myers
2004-11-18 19:11           ` Alex Rosenberg
2004-11-18  4:24   ` Matt Austern
2004-11-18  5:33 ` Dale Johannesen
2004-11-18 17:14 ` Fariborz Jahanian
2004-11-18 18:23   ` Joe Buck
2004-11-19  0:20     ` Ziemowit Laski
2004-11-19  0:40       ` Steven Bosscher
2004-11-19  1:20       ` Joe Buck
2004-11-19  2:00         ` Ziemowit Laski
2004-11-18 23:36 ` Ziemowit Laski
2004-11-18 23:37   ` Matt Austern
2004-11-18 23:49     ` Zack Weinberg
2004-11-19  1:38       ` Ziemowit Laski
2004-11-19  2:52         ` Zack Weinberg
2004-11-19  3:56           ` Ziemowit Laski
2004-11-19  4:22             ` Zack Weinberg
2004-11-19 13:10         ` Nathan Sidwell
2004-11-19 21:58           ` Ziemowit Laski
2004-11-18 23:44   ` Andrew Pinski
2004-11-18 23:45   ` Joe Buck
2004-11-25  4:42 ` Aaron W. LaFramboise

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=41A3B637.9030706@codesourcery.com \
    --to=nathan@codesourcery.com \
    --cc=Joe.Buck@synopsys.com \
    --cc=austern@apple.com \
    --cc=gcc@gcc.gnu.org \
    --cc=matz@suse.de \
    --cc=mrs@apple.com \
    --cc=pinskia@physics.uc.edu \
    --cc=snaroff@apple.com \
    --cc=zlaski@apple.com \
    /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).