From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id B76543858CDB for ; Wed, 24 May 2023 08:47:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B76543858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.20.4.52]) by gateway (Coremail) with SMTP id _____8Axres5z21kK10AAA--.830S3; Wed, 24 May 2023 16:47:54 +0800 (CST) Received: from [10.20.4.52] (unknown [10.20.4.52]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxWdI3z21kjY1zAA--.61038S2; Wed, 24 May 2023 16:47:51 +0800 (CST) 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. To: Xi Ruoyao , gcc-patches@gcc.gnu.org Cc: i@xen0n.name, xuchenghua@loongson.cn References: <20230524060407.19181-1-chenglulu@loongson.cn> <2d33bf204b0d59f16df8714123ee812be5754617.camel@xry111.site> From: Lulu Cheng Message-ID: <50e25f56-7b00-7b5b-60fe-3b9dac60bf27@loongson.cn> Date: Wed, 24 May 2023 16:47:51 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <2d33bf204b0d59f16df8714123ee812be5754617.camel@xry111.site> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8BxWdI3z21kjY1zAA--.61038S2 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7tFWfAr1DZr15Gr45Wr15Jwb_yoW8Aw4Upa y8Ka48Ka1kJr4xWr4UZa18ZFWSqrZ3XF1DJr95Jw1vvF1Ygr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_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 在 2023/5/24 下午2:45, Xi Ruoyao 写道: > On Wed, 2023-05-24 at 14:04 +0800, Lulu Cheng wrote: >> An empty struct type that is not non-trivial for the purposes of calls >> will be treated as though it were the following C type: >> >> struct { >>   char c; >> }; >> >> Before this patch was added, a structure parameter containing an empty structure and >> less than three floating-point members was passed through one or two floating-point >> registers, while nested empty structures are ignored. Which did not conform to the >> calling convention. > No, it's a deliberate decision I've made in > https://gcc.gnu.org/r12-8294. And we already agreed "the ABI needs to > be updated" when we applied r12-8294, but I've never improved my English > skill to revise the ABI myself :(. > > We are also using the same "de-facto" ABI throwing away the empty struct > for Clang++ (https://reviews.llvm.org/D132285). So we should update the > spec here, instead of changing every implementation. > > The C++ standard treats the empty struct as size 1 for ensuring the > semantics of pointer comparison operations. When we pass it through the > registers, there is no need to really consider the empty field because > there is no pointers to registers. > I think that the rules for passing parameters to empty structures or nested empty structures should be unified, but the current implementation in gcc is as follows(in C++): Compare the two structures,the current implementation is as follows: struct st1 {   struct empty {} e1;   long a;   long b; }; passed by reference. struct st2 {   struct empty {} e1;   double f0;   double f1; }; passed through two floating-point registers. Judging from the size of the structure, the size of st2 is already larger than 2xGRLEN, should be passed by reference.