public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: Aldy Hernandez <aldyh@redhat.com>,
	jason merrill <jason@redhat.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PR c++/78572] handle array self references in intializers
Date: Tue, 20 Dec 2016 17:21:00 -0000	[thread overview]
Message-ID: <5d83a71e-c451-1bb6-8886-e762c64a9395@acm.org> (raw)
In-Reply-To: <ad3c151e-9c4b-c203-89ab-3267417ab352@redhat.com>

On 12/20/2016 11:25 AM, Aldy Hernandez wrote:
> The problem in this PR is that we're trying to initialize an array with
> members of itself:

> Jakub has even gone further to show that for the following:
>
>     ... = { array[3]=5, array[7]=3, array[7]=8, array[7] = 9 };
>
> things get even worse, because we generate code to write twice into [3]:
>
>     {[3]=5, [0]=5, [7]=9, [1]=3, [2]=8, [3]=9}

I looked at this a couple of weeks ago, and got confused.  It wasn't 
very clear to me how the side-effect assignments interact with any 
implict zero assignments.  (Especially if one then tries to support 
C-style designated initializers).

IIUC the side effects of an initializer are evaluated before the storage 
of the initializer itself (separated by a sequence point).  further it 
seems that default zero initialization of non-explicitly initialized 
elements happens after any side-effected store to that element (and 
hence zaps the sideeffect).  The rules for non-aggregates appear to be 
as-if one builds a temporary object and then copy-constructs it into the 
object -- clearly zapping any and all side-effects.  However for 
aggregate initializations it looked like elements were initialized in 
order -- so the side effect on a later element could overwrite the 
initialization of an earlier element.

It wasn't entirely clear.

nathan
-- 
Nathan Sidwell

  reply	other threads:[~2016-12-20 16:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-20 16:42 Aldy Hernandez
2016-12-20 17:21 ` Nathan Sidwell [this message]
2016-12-20 18:58   ` Aldy Hernandez
2016-12-20 20:30     ` Nathan Sidwell
2016-12-21 17:41       ` Aldy Hernandez
2016-12-21 17:47         ` Jakub Jelinek

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=5d83a71e-c451-1bb6-8886-e762c64a9395@acm.org \
    --to=nathan@acm.org \
    --cc=aldyh@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.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).