public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: WANG Xuerui <i@xen0n.name>
To: Lulu Cheng <chenglulu@loongson.cn>,
	Jason Merrill <jason@redhat.com>,
	Jonathan Wakely <jwakely@redhat.com>
Cc: Xi Ruoyao <xry111@xry111.site>,
	gcc-patches@gcc.gnu.org, xuchenghua@loongson.cn
Subject: Re: [PATCH] LoongArch: Fix the problem of structure parameter passing in C++. This structure has empty structure members and less than three floating point members.
Date: Thu, 25 May 2023 10:52:42 +0800	[thread overview]
Message-ID: <59f5839a-bb1e-486a-8c1c-5410ea65360e@xen0n.name> (raw)
In-Reply-To: <e03f4334-0edc-faa2-b345-a9cddf56b23b@loongson.cn>


On 2023/5/25 10:46, Lulu Cheng wrote:
> 
> 在 2023/5/25 上午4:15, Jason Merrill 写道:
>> On Wed, May 24, 2023 at 5:00 AM Jonathan Wakely via Gcc-patches 
>> <gcc-patches@gcc.gnu.org <mailto:gcc-patches@gcc.gnu.org>> wrote:
>>
>>     On Wed, 24 May 2023 at 09:41, Xi Ruoyao <xry111@xry111.site> wrote:
>>
>>     > Wang Lei raised some concerns about Itanium C++ ABI, so let's
>>     ask a C++
>>     > expert here...
>>     >
>>     > Jonathan: AFAIK the standard and the Itanium ABI treats an empty
>>     class
>>     > as size 1
>>
>>     Only as a complete object, not as a subobject.
>>
>>
>> Also as a data member subobject.
>>
>>     > in order to guarantee unique address, so for the following:
>>     >
>>     > class Empty {};
>>     > class Test { Empty empty; double a, b; };
>>
>>     There is no need to have a unique address here, so Test::empty and
>>     Test::a
>>     have the same address. It's a potentially-overlapping subobject.
>>
>>     For the Itanium ABI, sizeof(Test) == 2 * sizeof(double).
>>
>>
>> That would be true if Test::empty were marked [[no_unique_address]], 
>> but without that attribute, sizeof(Test) is actually 3 * sizeof(double).
>>
>>     > When we pass "Test" via registers, we may only allocate the
>>     registers
>>     > for Test::a and Test::b, and complete ignore Test::empty because
>>     there
>>     > is no addresses of registers.  Is this correct or not?
>>
>>     I think that's a decision for the loongarch psABI. In principle,
>>     there's no
>>     reason a register has to be used to pass Test::empty, since you
>>     can't read
>>     from it or write to it.
>>
>>
>> Agreed.  The Itanium C++ ABI has nothing to say about how registers 
>> are allocated for parameter passing; this is a matter for the psABI.
>>
>> And there is no need for a psABI to allocate a register for 
>> Test::empty because it contains no data.
>>
>> In the x86_64 psABI, Test above is passed in memory because of its 
>> size ("the size of the aggregate exceeds two eightbytes...").  But
>>
>> struct Test2 { Empty empty; double a; };
>>
>> is passed in a single floating-point register; the Test2::empty 
>> subobject is not passed anywhere, because its eightbyte is classified 
>> as NO_CLASS, because there is no actual data there.
> 
> 
> 
>>
>> I know nothing about the LoongArch psABI, but going out of your way to 
>> assign a register to an empty class seems like a mistake.
> 
> MIPS64 and ARM64 also allocate parameter registers for empty structs. 
> https://godbolt.org/z/jT4cY3T5o
> 
> Our original intention is not to pass this empty structure member, but 
> to make the following two structures treat empty structure members
> 
> in the same way in the process of passing parameters.
> 
> struct st1
> {
>      struct empty {} e1;
>      long a;
>      long b;
> };
> 
> struct st2
> {
>      struct empty {} e1;
>      double f0;
>      double f1;
> };

Then shouldn't we try to avoid the extra register in all cases, instead 
of wasting one regardless? ;-)

  reply	other threads:[~2023-05-25  2:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24  6:04 Lulu Cheng
2023-05-24  6:45 ` Xi Ruoyao
2023-05-24  8:41   ` Xi Ruoyao
2023-05-24  8:59     ` Jonathan Wakely
2023-05-24 20:15       ` Jason Merrill
2023-05-25  2:46         ` Lulu Cheng
2023-05-25  2:52           ` WANG Xuerui [this message]
2023-05-25  3:41             ` Lulu Cheng
2023-05-25  8:23         ` Jonathan Wakely
2023-05-24  8:47   ` Lulu Cheng
2023-05-24  9:25     ` Xi Ruoyao
2023-05-24 10:07       ` Lulu Cheng
2023-05-24 14:55         ` Xi Ruoyao

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=59f5839a-bb1e-486a-8c1c-5410ea65360e@xen0n.name \
    --to=i@xen0n.name \
    --cc=chenglulu@loongson.cn \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=jwakely@redhat.com \
    --cc=xry111@xry111.site \
    --cc=xuchenghua@loongson.cn \
    /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).