public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Bernd Edlinger <bernd.edlinger@hotmail.de>,
	Richard Biener <rguenther@suse.de>,
	Jakub Jelinek <jakub@redhat.com>
Cc: Jonathan Wakely <jwakely@redhat.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	Jason Merrill <jason@redhat.com>, Jeff Law <law@redhat.com>
Subject: Re: [PATCH] Add a new type attribute always_alias (PR79671)
Date: Thu, 06 Apr 2017 18:19:00 -0000	[thread overview]
Message-ID: <1a0cdc64-3c65-4f2b-427d-8dcb90095cab@redhat.com> (raw)
In-Reply-To: <AM4PR0701MB2162B4A0AEF56BDEEC1247E0E40D0@AM4PR0701MB2162.eurprd07.prod.outlook.com>

On 04/06/2017 08:12 PM, Bernd Edlinger wrote:
> On 04/06/17 19:47, Florian Weimer wrote:
>> On 04/06/2017 07:39 PM, Bernd Edlinger wrote:
>>> On 04/06/17 16:17, Florian Weimer wrote:
>>>>> Here is what I want to write in the doc:
>>>>>
>>>>> @item typeless_storage
>>>>> @cindex @code{typeless_storage} type attribute
>>>>> A type declared with this attribute behaves like a character type
>>>>> with respect to aliasing semantics.
>>>>> This is attribute is similar to the @code{may_alias} attribute,
>>>>> except that it is not restricted to pointers.
>>>>
>>>> As Jakub pointed out, this is not what we need here.  An object of type
>>>> char does *not* have untyped storage.  Accessing it as a different type
>>>> is still undefined.
>>>>
>>>
>>> but, do you agree that this is valid in C11?
>>>
>>> typedef char char_a[4];
>>>
>>> int
>>> main (void)
>>> {
>>>    char_a a = {1,2,3,4};
>>>    short *b = (short *) &a;
>>>
>>>    b[1] = 0;
>>>
>>>    if (a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4)
>>>      abort();
>>>
>>>    exit(0);
>>> }
>>>
>>>
>>> all I want to do is replace "char" with a different type.
>>
>> Thanks a lot for posting a concrete example.
>>
>> The effective type of a[2] and [3] is char.  The character type wildcard
>> in 6.5(7) only applies to the type of the lvalue expression ysed for the
>> access, not the effective type of the object being accessed.  The type
>> of the LHS of the assignment expression is short.  So the access is
>> undefined.
>>
>
> exactly *that* is what I want to make valid with that attribute, which
> would be also useful in C and kernel code, IMHO.

And I think we all agree that this is a laudable goal.

> But isn't the effective type changed by the assignment b[1] = 0;
> as described in 6.5(6):
> "If a value is stored into an object having no declared type through an
> lvalue having a type that is not a character type, then the type of the
> lvalue becomes the effective type of the object for that access and for
> subsequent accesses that do not modify the stored value."

I don't know what your patch does, but your proposed documentation does 
not make this valid because “declared as char” is still not “having no 
declared type”.  Or put differently, “behaves like a character type” is 
not what we actually want here.

Let me repeat that I don't know if this is merely a documentation issue.

Thanks,
Florian

  reply	other threads:[~2017-04-06 18:19 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-05  9:46 Bernd Edlinger
2017-04-05 13:28 ` Jakub Jelinek
2017-04-05 15:20   ` Richard Biener
2017-04-05 17:41     ` Bernd Edlinger
2017-04-05 20:18       ` Jason Merrill
2017-04-05 20:46         ` Bernd Edlinger
2017-04-05 22:54           ` Pedro Alves
2017-04-06 10:08           ` Jonathan Wakely
2017-04-06  7:23         ` Richard Biener
2017-04-05 15:27   ` Bernd Edlinger
2017-04-05 15:29     ` Jakub Jelinek
2017-04-05 14:50 ` Florian Weimer
2017-04-05 15:23   ` Richard Biener
2017-04-05 15:38     ` Bernd Edlinger
2017-04-05 16:03       ` Jonathan Wakely
2017-04-05 16:08         ` Jakub Jelinek
2017-04-05 17:23           ` Bernd Edlinger
2017-04-05 21:02             ` Bernd Edlinger
2017-04-05 23:17               ` Sandra Loosemore
2017-04-06  5:40                 ` Jakub Jelinek
2017-04-06  7:47               ` Richard Biener
2017-04-06  7:51                 ` Jakub Jelinek
2017-04-06  7:55                   ` Richard Biener
2017-04-06 14:11                     ` Bernd Edlinger
2017-04-06 14:17                       ` Florian Weimer
2017-04-06 14:23                         ` Richard Biener
2017-04-06 14:43                           ` Jonathan Wakely
2017-04-06 14:51                             ` Florian Weimer
2017-04-06 15:05                               ` Jakub Jelinek
2017-04-06 15:10                                 ` Florian Weimer
2017-04-06 19:13                               ` Richard Biener
2017-04-11 10:43                                 ` Florian Weimer
2017-04-11 10:48                                   ` Richard Biener
2017-04-06 17:39                         ` Bernd Edlinger
2017-04-06 17:48                           ` Florian Weimer
2017-04-06 18:12                             ` Bernd Edlinger
2017-04-06 18:19                               ` Florian Weimer [this message]
2017-04-06 18:49                                 ` Bernd Edlinger
2017-04-06 19:05                                   ` Florian Weimer
2017-04-06 19:20                                     ` Bernd Edlinger
2017-04-07  6:47                                       ` Richard Biener
2017-04-07 12:58                                         ` Bernd Edlinger
2017-04-06 19:16                               ` Richard Biener
2017-04-07  6:56                                 ` Florian Weimer
2017-04-07  8:01                                   ` Richard Biener
2017-04-06 19:14                           ` Richard Biener
2017-04-06 19:51                             ` Bernd Edlinger
2017-04-06 14:22                       ` Richard Biener
2017-04-06 21:00                 ` Bernd Edlinger
2017-04-07  6:54                   ` Richard Biener
2017-04-07 13:37                     ` Bernd Edlinger
2017-04-07 15:10                       ` Richard Biener
2017-04-07 15:33                         ` Bernd Edlinger
2017-04-07 20:22                           ` Jason Merrill
2017-04-10 12:50                             ` Richard Biener
2017-04-10 14:41                               ` Jason Merrill
2017-04-10 15:31                                 ` Richard Biener
2017-04-10 16:35                                   ` Jason Merrill
2017-04-11 10:32                                     ` Richard Biener
2017-04-11 11:53                                       ` Richard Biener
2017-04-11 13:35                                         ` Richard Biener
2017-04-11 18:47                                           ` Jason Merrill
2017-04-10 21:40                               ` Pedro Alves
2017-04-11  7:37                                 ` Richard Biener
2017-04-06 20:20               ` Bernd Edlinger

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=1a0cdc64-3c65-4f2b-427d-8dcb90095cab@redhat.com \
    --to=fweimer@redhat.com \
    --cc=bernd.edlinger@hotmail.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    --cc=jwakely@redhat.com \
    --cc=law@redhat.com \
    --cc=rguenther@suse.de \
    /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).