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: chenglulu X-Patchwork-Id: 98303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2624177vqo; Tue, 23 May 2023 23:05:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Tm2neeVKYQJzf2gjSCf29jwh00kw3uLpmTELadQ1w+76cpdcc3/xbtaIFlXeOyO+Y8frT X-Received: by 2002:a05:6402:1615:b0:50d:9f1b:db77 with SMTP id f21-20020a056402161500b0050d9f1bdb77mr987654edv.33.1684908313591; Tue, 23 May 2023 23:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684908313; cv=none; d=google.com; s=arc-20160816; b=pyx77pz9ovsjar/QOTlqYVzr3M6YoGn89enbQBD1TzZExUDJmylDbwxUuRyFxCwKOP FQL8wYNRONfGnXg8EUfz2sc6l7mMTBywNnKDV0oEdKFaaYJyXvKMRA9zh6XQiiStOGk2 UoBueTsGnAQh/++7gREa4KytLNlwcr48YRaldgjQ4Gpi7q8URydgwnArl3k7IwSIenWi vJuhvaSqxXDBbpkonjU8c9CoPXLoghkxngKGO/7dEf0vM6kXJhuAQBAqUuEXNXu3R0aL FVJw6KtE6uDQ3y/K+TRpL4+RzCQ/BMJKS8OOfkgA64RYt4XMq30oEtu9erOAQ0/4vQZs maLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dmarc-filter :delivered-to; bh=SnCplEzcQGaba0zRB/QUPkEJXyQG6YPKuStOsFAcaA0=; b=wUrCB11fTnFkYK8SecCsbH6cWWVTmQRTIZZidUrq6nn1Glr1XFaJHH+IuiHtBKz46B +ztI/+5VoATp1uTX4VJLUgojczf+nFcsSwqrbK5a1FJU1uMEKLqP9ZmDYIVa2e7eyzIC BrwOhDIE0veMG90gai8uypRL4QAYo1/5kpcjz6aBQq88W6rkYz4qkd0s0bcV1NXCyvOC ShpYgtvyQzmq80XIqQNk8gIcvu7F4AEL89LFHDQF74pLd9fZjm9bhk94jzJNHWTjvidE JgdVk/neIl+5aThIRNPz4EpgVe9k1ZQOnOMAhmU5zp/OuCccOPyzEfcL9pZ10zwkrNhF QSJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b17-20020aa7d491000000b005022d0268f3si1397850edr.669.2023.05.23.23.05.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 23:05:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B61B3385772F for ; Wed, 24 May 2023 06:05:08 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766754419388341380?= X-GMAIL-MSGID: =?utf-8?q?1766754419388341380?= 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); +}