From patchwork Wed May 24 06:04:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cheng X-Patchwork-Id: 1785535 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QR0yj3tz9z20PY for ; Wed, 24 May 2023 16:05:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B6083857719 for ; Wed, 24 May 2023 06:04:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 52E823858D37 for ; Wed, 24 May 2023 06:04:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52E823858D37 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.2.5.5]) by gateway (Coremail) with SMTP id _____8Bxy_L3qG1k41EAAA--.991S3; Wed, 24 May 2023 14:04:40 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx8a_zqG1kEyRzAA--.61253S2; Wed, 24 May 2023 14:04:39 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, Lulu Cheng Subject: [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: Wed, 24 May 2023 14:04:08 +0800 Message-Id: <20230524060407.19181-1-chenglulu@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx8a_zqG1kEyRzAA--.61253S2 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxCw4xXry5ZFy5WFW7try7KFg_yoWrWw1xpa y7AryFyr48JFZ7GrnxG343Xrsaqr1xWr1a9asIyryvvF12yryfZF18K3srZF13Ja1UXr1I qw4F93Wjga1UWa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b7AYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4xG64xvF2 IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4U McvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr 0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8czVUUUUUU== X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_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 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. After adding this patch, empty structs will always be passed. gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_flatten_aggregate_field): Mark out nested empty structs. (loongarch_pass_aggregate_in_fpr_and_gpr_p): If an empty structure exists, increment the number of fixed-point registers required. gcc/testsuite/ChangeLog: * g++.target/loongarch/empty1.C: New test. * g++.target/loongarch/empty2.C: New test. * g++.target/loongarch/empty3.C: New test. --- gcc/config/loongarch/loongarch.cc | 13 +++++++++++++ gcc/testsuite/g++.target/loongarch/empty1.C | 18 ++++++++++++++++++ gcc/testsuite/g++.target/loongarch/empty2.C | 20 ++++++++++++++++++++ gcc/testsuite/g++.target/loongarch/empty3.C | 19 +++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 gcc/testsuite/g++.target/loongarch/empty1.C create mode 100644 gcc/testsuite/g++.target/loongarch/empty2.C create mode 100644 gcc/testsuite/g++.target/loongarch/empty3.C diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 7f4e0e59573..77506410501 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -321,6 +321,18 @@ loongarch_flatten_aggregate_field (const_tree type, || !tree_fits_uhwi_p (TYPE_SIZE (type))) return -1; + if (default_is_empty_record (type)) + { + if (n < 2) + { + fields[n].type = type; + fields[n].offset = offset; + return n + 1; + } + else + return -1; + } + for (tree f = TYPE_FIELDS (type); f; f = DECL_CHAIN (f)) if (TREE_CODE (f) == FIELD_DECL) { @@ -458,6 +470,7 @@ loongarch_pass_aggregate_in_fpr_and_gpr_p (const_tree type, { num_float += SCALAR_FLOAT_TYPE_P (fields[i].type); num_int += INTEGRAL_TYPE_P (fields[i].type); + num_int += (TREE_CODE (fields[i].type) == RECORD_TYPE); } return num_int == 1 && num_float == 1; diff --git a/gcc/testsuite/g++.target/loongarch/empty1.C b/gcc/testsuite/g++.target/loongarch/empty1.C new file mode 100644 index 00000000000..059e6774158 --- /dev/null +++ b/gcc/testsuite/g++.target/loongarch/empty1.C @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mabi=lp64d" } */ +/* { dg-final { scan-assembler-times "ld.bu\t\\\$r4,\\\$r12,0" 1 } } */ + +struct E {}; +struct s1 +{ + struct E {} e1; + float f0; +}; + +extern void fun (struct s1); + +struct s1 s1_1 = {{}, 1.0}; +void test (void) +{ + fun (s1_1); +} diff --git a/gcc/testsuite/g++.target/loongarch/empty2.C b/gcc/testsuite/g++.target/loongarch/empty2.C new file mode 100644 index 00000000000..abf01de751a --- /dev/null +++ b/gcc/testsuite/g++.target/loongarch/empty2.C @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mabi=lp64d" } */ +/* { dg-final { scan-assembler-not "fld.s" } } */ +/* { dg-final { scan-assembler-not "fld.d" } } */ + +struct E {}; +struct s1 +{ + struct E {} e1; + float f0; + double f1; +}; + +extern void fun (struct s1); + +struct s1 s1_1 = {{}, 1.0, 2.0}; +void test (void) +{ + fun (s1_1); +} diff --git a/gcc/testsuite/g++.target/loongarch/empty3.C b/gcc/testsuite/g++.target/loongarch/empty3.C new file mode 100644 index 00000000000..8c40963238b --- /dev/null +++ b/gcc/testsuite/g++.target/loongarch/empty3.C @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mabi=lp64d" } */ +/* { dg-final { scan-assembler-not "fld.d" } } */ + +struct E {}; +struct s1 +{ + struct E {} e1; + double f0; + double f1; +}; + +extern void fun (struct s1); + +struct s1 s1_1 = {{}, 1.0, 2.0}; +void test (void) +{ + fun (s1_1); +}