Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] Add constructor and destructor to thread_info
Date: Tue, 28 Mar 2017 22:35:00 -0000	[thread overview]
Message-ID: <577b5d2b-a122-5318-745e-3d19843a5ea4@redhat.com> (raw)
In-Reply-To: <86efxho1f2.fsf@gmail.com>

On 03/28/2017 04:40 PM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
> 
>>>>  - struct target_waitstatus pending_follow;
>>>>  + struct target_waitstatus pending_follow {TARGET_WAITKIND_SPURIOUS};
>>>>
>>>
>>> This will only initialize the first member of union
>>> target_waitstatus.value to zero, so some bits of
>>> target_waitstatus.value.related_pid is not initialized.
>>
>> Ah, blah, unions.  Well, the result is that the remaining fields of
>> the struct end up list->value->zero-initialized.  Zero-initialization
>> for unions means the first member is zero-initialized, and padding
>> is initialized to zero.  So I think the end result is the
>> same anyway.
> 
> It is different from
> "memset (&this->pending_follow, 0, sizeof (this->pending_follow))".  The
> first member "integer" is zero-initialized, but it is not the largest
> member, so part of "related_pid" is not zero-initialized.
> 
>   |<------------------ union----------------->|
>   |<------- related_pid ------->|<- padding ->|
>   |<- integer ->|
>   |      0      |<uninitialized>|     0       |
> 

I'm not so sure about that.  That is not my interpretation,
though the standard isn't crystal clear here.  The definition
of "padding" is left vague.  It doesn't look like that's the
interpretation of either G++ nor Clang though.  G++ always zeroes
the whole object, while Clang initializes only the first member,
leaving everything else uninitialized, which I found surprising,
since no padding _at all_ of any kind is initialized then.

I've sent an inquiry to std-discussion at isocpp.org list earlier
today, though I haven't gotten an answer yet.  See:

  https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/ljaMNnkahHA

Though given Clang's behavior, it's probably not a good idea to assume
everything's zeroed out.

target_waitstatus would be a natural fit for something like
C++17's std::variant.  Particularly, the lifetime of value.execd_pathname is
not well defined...  Let's go with what you had, and revisit if/when we
change/fix target_waitstatus.

Thanks,
Pedro Alves


  reply	other threads:[~2017-03-28 22:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-28  8:24 [PATCH 0/2] Fix thread_info refcount Yao Qi
2017-03-28  8:24 ` [PATCH 2/2] Delete thread_info is refcount is zero Yao Qi
2017-03-28 12:10   ` Pedro Alves
2017-04-05 21:15     ` [PATCH 0/2] Don't delete thread_info if refcount isn't zero Yao Qi
2017-04-05 21:15       ` [PATCH 1/2] Hoist code on marking thread as exited Yao Qi
2017-04-06  9:27         ` Pedro Alves
2017-04-05 21:15       ` [PATCH 2/2] Don't delete thread_info if refcount isn't zero Yao Qi
2017-04-06 10:18         ` Pedro Alves
2017-04-07  9:22           ` Yao Qi
2017-04-07 10:29             ` Pedro Alves
2017-04-10 13:40               ` Yao Qi
2017-04-10 14:50                 ` [pushed] GC gdb/thread.c:current_thread_cleanup_chain (Re: [PATCH 2/2] Don't delete thread_info if refcount isn't zero) Pedro Alves
2017-04-10 15:57           ` [PATCH 2/2] Don't delete thread_info if refcount isn't zero Pedro Alves
     [not found] ` <1490689483-16084-2-git-send-email-yao.qi@linaro.org>
2017-03-28 12:12   ` [PATCH 1/2] Add constructor and destructor to thread_info Pedro Alves
2017-03-28 14:08     ` Yao Qi
2017-03-28 14:47       ` Pedro Alves
2017-03-28 15:40         ` Yao Qi
2017-03-28 22:35           ` Pedro Alves [this message]
2017-03-29 15:59             ` Yao Qi

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=577b5d2b-a122-5318-745e-3d19843a5ea4@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@gmail.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