From patchwork Mon Jan 9 10:32:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 40788 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2078695wrt; Mon, 9 Jan 2023 02:33:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXthXnU9R4sD7GfGWBcqlhddNG0eb1+Jlnrdh72OFc6d9wRU6yTEt8T/NKxkzSj4xu2p8FDx X-Received: by 2002:aa7:cb4b:0:b0:491:3a5c:6e5 with SMTP id w11-20020aa7cb4b000000b004913a5c06e5mr18724581edt.1.1673260411673; Mon, 09 Jan 2023 02:33:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673260411; cv=none; d=google.com; s=arc-20160816; b=dqGup9MkRh8/JZOxvLNskzNbKVBn3VNXdLcEYQNlCyGf7zxj+t3CTSrEISnwuU6hi3 AqJFC42oxuiyAHqYi53Uyj2leeiE8wRehLf7anifW1Lgxt66MBTm8KTUw86MNNr7t8Qd RUYNTg1zVjpcOY7klpexIRFBMyAv3juNbHyhBGJ/pGowQw84UMNnJF2iRlZ1bp68ua8b lZecCX547QYNB7TPFkWXaKuOpWkRDerXaEHYAKwrv8MCfEbajsAPKCT96Cj3gVAxmsUd BhlEm0Z5UzY5fYz16bpcrZoOkBLFCrKBkvSLjKmr9claS8ToEBC0zyy0TpRxTBhtFXWf lMvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=HCbgYssWx8F8snpYObr13jLS2jq+0bKNdOemZPMG9PQ=; b=eCH2blR203zyrGz8/XTLt5hBMHVWNR8DcdPwBVYc9b13HsmzWBS7W6taDeg2j1ABoP nLlH2tHLL80GST2rURYK7Xd1qJRxT0chenvmDzi+2Z87A1q9y+gD0x5ypRy6Iynwyj5P FEOjbNyiO3rfWV14jPLjMVD3qJQNh9OiBoDAdJQPQIeLnFhIFMwpdzhw3zqQXgkXmtNf pJIANGhx9JbClFtoAN79L87j6D9akuo62u/mFg7vShQbcM2/anjpnXmCcMyAbT+9dP7y jEnWZQg/Vk+mP3ArYw8hnBXxMej0Y7pu8T7+A0+FGA8y7HUN2UIxvNDMKmolHpDati5K X3/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Sx3SFb5S; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id p13-20020aa7cc8d000000b00457f31c1a10si8020868edt.584.2023.01.09.02.33.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 02:33:31 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Sx3SFb5S; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 786763858D20 for ; Mon, 9 Jan 2023 10:33:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 786763858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673260410; bh=HCbgYssWx8F8snpYObr13jLS2jq+0bKNdOemZPMG9PQ=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Sx3SFb5SXsSkGzWTiAzAy/jg1oFO7q4L90kqvSSTz+fjUIw+iKStFZ5DlwDKoTk+v d/uR9VAXoNAR3/WiryTY7p/ez6YTUTT2QkGtuMSpPW6NXh16ArcMGsCK+29dVMnjsN CdgHh2fBHVE64CWHV2wzkzCfG0fEmRrHzHFyUZz8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 985693858D37 for ; Mon, 9 Jan 2023 10:32:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 985693858D37 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-94-uM3HF_0GP-KaIBsaD6Bh_w-1; Mon, 09 Jan 2023 05:32:44 -0500 X-MC-Unique: uM3HF_0GP-KaIBsaD6Bh_w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CA0043814584; Mon, 9 Jan 2023 10:32:43 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 856C02026D4B; Mon, 9 Jan 2023 10:32:43 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 309AWZNj2666219 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 9 Jan 2023 11:32:40 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 309AWXA22666218; Mon, 9 Jan 2023 11:32:33 +0100 Date: Mon, 9 Jan 2023 11:32:33 +0100 To: "Joseph S. Myers" , Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] calls: Fix up TYPE_NO_NAMED_ARGS_STDARG_P handling [PR107453] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek 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?1754540709430135580?= X-GMAIL-MSGID: =?utf-8?q?1754540709430135580?= Hi! On powerpc64le-linux, the following patch fixes -FAIL: gcc.dg/c2x-stdarg-4.c execution test -FAIL: gcc.dg/torture/c2x-stdarg-split-1a.c -O0 execution test -FAIL: gcc.dg/torture/c2x-stdarg-split-1a.c -O1 execution test -FAIL: gcc.dg/torture/c2x-stdarg-split-1a.c -O2 execution test -FAIL: gcc.dg/torture/c2x-stdarg-split-1a.c -O2 -flto -fno-use-linker-plugin -flto-partition=none execution test -FAIL: gcc.dg/torture/c2x-stdarg-split-1a.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects execution test -FAIL: gcc.dg/torture/c2x-stdarg-split-1a.c -O3 -g execution test -FAIL: gcc.dg/torture/c2x-stdarg-split-1a.c -Os execution test The problem is mismatch between the caller and callee side. On the callee side, we do: /* NAMED_ARG is a misnomer. We really mean 'non-variadic'. */ if (!cfun->stdarg) data->arg.named = 1; /* No variadic parms. */ else if (DECL_CHAIN (parm)) data->arg.named = 1; /* Not the last non-variadic parm. */ else if (targetm.calls.strict_argument_naming (all->args_so_far)) data->arg.named = 1; /* Only variadic ones are unnamed. */ else data->arg.named = 0; /* Treat as variadic. */ which is later passed to the target hooks to determine if a particular argument is named or not. Now, cfun->stdarg is determined from the stdarg_p call, which for the new C2X TYPE_NO_NAMED_ARGS_STDARG_P function types (rettype fn (...)) returns true. Such functions have no named arguments, so data->arg.named will be 0 in function.cc. But on the caller side, as TYPE_NO_NAMED_ARGS_STDARG_P function types have TYPE_ARG_TYPES NULL, we instead treat those calls as unprototyped even when they are prototyped - /* If we know nothing, treat all args as named. */ n_named_args = num_actuals; in 2 spots. We need to treat the TYPE_NO_NAMED_ARGS_STDARG_P cases as prototyped with no named arguments. Bootstrapped/regtested on x86_64-linux, i686-linux, powerpc64le-linux (where it fixes the above failures), aarch64-linux and s390x-linux, ok for trunk? 2023-01-09 Jakub Jelinek PR target/107453 * calls.cc (expand_call): For calls with TYPE_NO_NAMED_ARGS_STDARG_P (funtype) use zero for n_named_args. Formatting fix. Jakub --- gcc/calls.cc.jj 2023-01-02 09:32:28.834192105 +0100 +++ gcc/calls.cc 2023-01-06 14:52:14.740594896 +0100 @@ -2908,8 +2908,8 @@ expand_call (tree exp, rtx target, int i } /* Count the arguments and set NUM_ACTUALS. */ - num_actuals = - call_expr_nargs (exp) + num_complex_actuals + structure_value_addr_parm; + num_actuals + = call_expr_nargs (exp) + num_complex_actuals + structure_value_addr_parm; /* Compute number of named args. First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */ @@ -2919,6 +2919,8 @@ expand_call (tree exp, rtx target, int i = (list_length (type_arg_types) /* Count the struct value address, if it is passed as a parm. */ + structure_value_addr_parm); + else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype)) + n_named_args = 0; else /* If we know nothing, treat all args as named. */ n_named_args = num_actuals; @@ -2957,6 +2959,8 @@ expand_call (tree exp, rtx target, int i && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far)) /* Don't include the last named arg. */ --n_named_args; + else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype)) + n_named_args = 0; else /* Treat all args as named. */ n_named_args = num_actuals;