From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 854333858D28 for ; Mon, 25 Apr 2022 07:22:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 854333858D28 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 [10.20.4.52] (unknown [10.20.4.52]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxjxNBTGZisaAwAA--.62913S2; Mon, 25 Apr 2022 15:22:42 +0800 (CST) Subject: Re: [PATCH] loongarch: ignore zero-size fields in calling convention To: Xi Ruoyao , Xi Ruoyao via Gcc-patches Cc: Chenghua Xu , Xuerui Wang References: <4ec7e7a716cb0ca090983f0400c99c50bc67bcb3.camel@mengyan1223.wang> <0b6d4a0f77bf88df6ad2182c1f56c77573f2e336.camel@mengyan1223.wang> From: Lulu Cheng Message-ID: <8b0045aa-df0f-e217-58c7-a31e466fd1cc@loongson.cn> Date: Mon, 25 Apr 2022 15:22:41 +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: <0b6d4a0f77bf88df6ad2182c1f56c77573f2e336.camel@mengyan1223.wang> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID: AQAAf9DxjxNBTGZisaAwAA--.62913S2 X-Coremail-Antispam: 1UD129KBjvJXoW3Ar4kCr4fWr17Kw1kuF15Jwb_yoW7ZFyDpF s7AFW5KrW8Jrn3Grn2q3W5XryrXr1xK347uw1ftFy0yr42yry0g3W0qr9F9F17Jw4vgr18 Zr4IgrWa9F1UZ3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvq14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26F4UJVW0owA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvEwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7I2V7IY0VAS07AlzVAY IcxG8wCY02Avz4vE-syl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2 IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v2 6r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2 IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrJr0_WFyUJwCI42IY6I8E 87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0x ZFpf9x0JUywZ7UUUUU= X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Apr 2022 07:22:50 -0000 This modification will cause the ABI to change, we are discussing solutions. And we will give a conclusion at the latest tommorrow. Thanks! 在 2022/4/25 下午1:57, Xi Ruoyao 写道: > Ping. > > Normally we shouldn't ping a patch after only a few days, but we're > running out of time to catch GCC 12 milestone. And once GCC 12 is > released the patch will become far more complicated for a psABI warning. > > And please note that the ABI difference between GCC and G++ should be > considered a bug, and it has to be fixed anyway. If you don't like the > idea of this patch, please develop another solution and apply it *before > GCC 12*. > > On Wed, 2022-04-20 at 14:23 +0800, Xi Ruoyao via Gcc-patches wrote: >> Currently, LoongArch ELF psABI is not clear on the handling of zero- >> sized fields in aggregates arguments or return values [1].  The behavior >> of GCC trunk is puzzling considering the following cases: >> >> struct test1 >> { >>   double a[0]; >>   float x; >> }; >> >> struct test2 >> { >>   float a[0]; >>   float x; >> }; >> >> GCC trunk passes test1::x via GPR, but test2::x via FPR.  I believe no >> rational Homo Sapiens can understand (or even expect) this. >> >> And, to make things even worse, test1 behaves differently in C and C++. >> GCC trunk passes test1::x via GPR, but G++ trunk passes test1::x via >> FPR. >> >> I've write a paragraph about current GCC behavior for the psABI [2], but >> I think it's cleaner to just ignore all zero-sized fields in the ABI. >> This will require only a two-line change in GCC (this patch), and an >> one-line change in the ABI doc. >> >> If there is not any better idea I'd like to see this reviewed and >> applied ASAP.  If we finally have to apply this patch after GCC 12 >> release, we'll need to add a lot more boring code to emit a -Wpsabi >> inform [3].  That will be an unnecessary burden for both us, and the >> users using the compiler (as the compiler will spend CPU time only for >> checking if a warning should be informed). >> >> [1]:https://github.com/loongson/LoongArch-Documentation/issues/48 >> [2]:https://github.com/loongson/LoongArch-Documentation/pull/49 >> [3]:https://gcc.gnu.org/PR102024 >> >> gcc/ >> >>         * config/loongarch/loongarch.cc >>         (loongarch_flatten_aggregate_field): Ignore empty fields for >>         RECORD_TYPE. >> >> gcc/testsuite/ >> >>         * gcc.target/loongarch/zero-size-field-pass.c: New test. >>         * gcc.target/loongarch/zero-size-field-ret.c: New test. >> --- >>  gcc/config/loongarch/loongarch.cc             |  3 ++ >>  .../loongarch/zero-size-field-pass.c          | 30 +++++++++++++++++++ >>  .../loongarch/zero-size-field-ret.c           | 28 +++++++++++++++++ >>  3 files changed, 61 insertions(+) >>  create mode 100644 gcc/testsuite/gcc.target/loongarch/zero-size-field-pass.c >>  create mode 100644 gcc/testsuite/gcc.target/loongarch/zero-size-field-ret.c >> >> diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc >> index f22150a60cc..57e4d9f82ce 100644 >> --- a/gcc/config/loongarch/loongarch.cc >> +++ b/gcc/config/loongarch/loongarch.cc >> @@ -326,6 +326,9 @@ loongarch_flatten_aggregate_field (const_tree type, >>        for (tree f = TYPE_FIELDS (type); f; f = DECL_CHAIN (f)) >>         if (TREE_CODE (f) == FIELD_DECL) >>           { >> +           if (DECL_SIZE (f) && integer_zerop (DECL_SIZE (f))) >> +             continue; >> + >>             if (!TYPE_P (TREE_TYPE (f))) >>               return -1; >> >> diff --git a/gcc/testsuite/gcc.target/loongarch/zero-size-field-pass.c b/gcc/testsuite/gcc.target/loongarch/zero-size-field-pass.c >> new file mode 100644 >> index 00000000000..999dc913a71 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/loongarch/zero-size-field-pass.c >> @@ -0,0 +1,30 @@ >> +/* Test that LoongArch backend ignores zero-sized fields of aggregates in >> +   argument passing.  */ >> + >> +/* { dg-do compile } */ >> +/* { dg-options "-O2 -mdouble-float -mabi=lp64d" } */ >> +/* { dg-final { scan-assembler "\\\$f1" } } */ >> + >> +struct test >> +{ >> +  int empty1[0]; >> +  double empty2[0]; >> +  int : 0; >> +  float x; >> +  long empty3[0]; >> +  long : 0; >> +  float y; >> +  unsigned : 0; >> +  char empty4[0]; >> +}; >> + >> +extern void callee (struct test); >> + >> +void >> +caller (void) >> +{ >> +  struct test test; >> +  test.x = 114; >> +  test.y = 514; >> +  callee (test); >> +} >> diff --git a/gcc/testsuite/gcc.target/loongarch/zero-size-field-ret.c b/gcc/testsuite/gcc.target/loongarch/zero-size-field-ret.c >> new file mode 100644 >> index 00000000000..40137d97555 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/loongarch/zero-size-field-ret.c >> @@ -0,0 +1,28 @@ >> +/* Test that LoongArch backend ignores zero-sized fields of aggregates in >> +   returning.  */ >> + >> +/* { dg-do compile } */ >> +/* { dg-options "-O2 -mdouble-float -mabi=lp64d" } */ >> +/* { dg-final { scan-assembler-not "\\\$r4" } } */ >> + >> +struct test >> +{ >> +  int empty1[0]; >> +  double empty2[0]; >> +  int : 0; >> +  float x; >> +  long empty3[0]; >> +  long : 0; >> +  float y; >> +  unsigned : 0; >> +  char empty4[0]; >> +}; >> + >> +extern struct test callee (void); >> + >> +float >> +caller (void) >> +{ >> +  struct test test = callee (); >> +  return test.x + test.y; >> +}