From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 24CE13858C52 for ; Thu, 29 Feb 2024 17:51:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24CE13858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 24CE13858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709229067; cv=none; b=ooDKnU4eUZ5k/Ni6MVNVR+OPmRJkL4cZK8Yh/qqrxZ8M3gUXugN7gJiDUnuNkyFX7h11X6C2L828hghE3UO+K4QJmPHdZ8zfFq50Fv+m7i5Z/u1qVl+KRcO0Q6X9XD/x0F1YrWPBe29gkYQQbqo9N4NtAtPlRie0uNQgHptI6uE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709229067; c=relaxed/simple; bh=3xntGvqjrgWCMyR+5n559dESZYKM+XgzXiLEyi3ICRY=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=S1GEEmg5ngaPGE3jwCCebkgOdEuZZWlULOiLVS7yuS+QUEcS1C06ZI6rKwlExLYRa9lkvTa0utNFRcm2gxgOwdbyVA6Q1uAkN36YWLT4hQQkPxjF2muchIof1D3TKE9zE+pXKQlYCa9i6R6v+zJ1hP2joI0tTwxbalG6S165fFo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8E68D1FB; Thu, 29 Feb 2024 09:51:44 -0800 (PST) Received: from [10.2.78.54] (e120077-lin.cambridge.arm.com [10.2.78.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A06153F73F; Thu, 29 Feb 2024 09:51:04 -0800 (PST) Message-ID: Date: Thu, 29 Feb 2024 17:51:03 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] calls: Further fixes for TYPE_NO_NAMED_ARGS_STDARG_P handling [PR107453] Content-Language: en-GB To: Jakub Jelinek Cc: "Joseph S. Myers" , Richard Biener , Jeff Law , gcc-patches@gcc.gnu.org, =?UTF-8?Q?Torbj=C3=B6rn_SVENSSON?= , oliva@adacore.com References: <45ac2d54-21df-486c-a085-0a6c1f37a323@arm.com> <23c7c873-1954-43b2-80b8-714455eaaf2b@arm.com> <9b4f43f8-3807-432f-b1a2-e0515ab198ca@arm.com> From: "Richard Earnshaw (lists)" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3491.6 required=5.0 tests=BAYES_00,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 29/02/2024 17:38, Jakub Jelinek wrote: > On Thu, Feb 29, 2024 at 05:23:25PM +0000, Richard Earnshaw (lists) wrote: >> On 29/02/2024 15:55, Jakub Jelinek wrote: >>> On Thu, Feb 29, 2024 at 02:14:05PM +0000, Richard Earnshaw wrote: >>>>> I tried the above on arm, aarch64 and x86_64 and that seems fine, >>>>> including the new testcase you added. >>>>> >>>> >>>> I should mention though, that INIT_CUMULATIVE_ARGS on arm ignores >>>> n_named_args entirely, it doesn't need it (I don't think it even existed >>>> when the AAPCS code was added). >>> >>> So far I've just checked that the new testcase passes not just on >>> x86_64/i686-linux, but also on {powerpc64le,s390x,aarch64}-linux >>> with vanilla trunk. >>> Haven't posted this patch in patch form, plus while I'm not really sure >>> whether setting n_named_args to 0 or not changing in the >>> !pretend_outgoing_varargs_named is right, the setting to 0 feels more >>> correct to me. If structure_value_addr_parm is 1, the function effectively >>> has a single named argument and then ... args and if the target wants >>> n_named_args to be number of named arguments except the last, then that >>> should be 0 rather than 1. >>> >>> Thus, is the following patch ok for trunk then? >> >> The comment at the start of the section says >> >> /* Now possibly adjust the number of named args. >> Normally, don't include the last named arg if anonymous args follow. >> We do include the last named arg if >> targetm.calls.strict_argument_naming() returns nonzero. >> (If no anonymous args follow, the result of list_length is actually >> one too large. This is harmless.) >> >> So in the case of strict_argument_naming perhaps it should return 1, but 0 for other cases. > > The TYPE_NO_NAMED_ARGS_STDARG_P (funtype) case is as if type_arg_types != 0 > and list_length (type_arg_types) == 0, i.e. no user named arguments. > As list_length (NULL) returns 0, perhaps it could be even handled just the > by changing all the type_arg_types != 0 checks to > type_arg_types != 0 || TYPE_NO_NAMED_ARGS_STDARG_P (funtype) > There are just 2 cases I'm worried about, one is that I think rest of > calls.cc nor the backends are prepared to see n_named_args -1 after the > adjustments, I think it is better to use 0, and then the question is what > the !strict_argument_naming && !pretend_outgoing_varargs_named case > wants to do for the aggregate return. The patch as posted for > void foo (...); void bar () { foo (1, 2, 3); } > will set n_named_args initially to 0 (no named args) and with the > adjustments for strict_argument_naming 0, otherwise for !pretend > 0 as well, otherwise 3. > For > struct { char buf[4096]; } baz (...); void qux () { baz (1, 2, 3); } > the patch sets n_named_args initially to 1 (the hidden return) and > with the arguments for strict keep it at 1, for !pretend 0 and otherwise > 3. > > So, which case do you think is handled incorrectly with that? The way I was thinking about it (and testing it on Arm) was to look at n_named_args for the cases of a traditional varargs case, then reduce that by one (except it can't ever be negative). So for void f(...); void g(int, ...); struct S { int a[32]; }; struct S h (...); struct S i (int, ...); void a () { struct S x; f(1, 2, 3, 4); g(1, 2, 3, 4); x = h (1, 2, 3, 4); x = i (1, 2, 3, 4); } There are various permutations that could lead to answers of 0, 1, 2, 4 and 5 depending on how those various targets treat each case and how the result pointer address is handled. My suspicion is that for a target that has strict argument naming and the result pointer passed as a first argument, the answer for the 'h()' call should be 1, not zero. Oh, but wait! Perhaps that now falls into the initial 'if' clause and we never reach the point where you pick zero. So perhaps I'm worrying about nothing. R. > > Jakub >