From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 1AF1F3857C58; Tue, 12 Dec 2023 20:23:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AF1F3857C58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702412615; bh=l5klQdk6YrbB4rIjNNpngJQyQqgVQrcLRmpyxRGHiFk=; h=From:To:Subject:Date:From; b=GWDNPRgIuRa8J6aUcpz2GWoU2c+jdpi1xT5xT2b6f7fI2CeXZbXeYix/fnHRchnb9 46SXuPPvhiswmfryPNOe/4/ANkZ0blKtlL68I0eH4HU7HhTrdqZdZt83+SuhMdGykX vK2XpRyMvw0JnU0IdNTgFdPdLnJVDJku4Ap6ca60= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] arm: fix c23 0-named-args caller-side stdarg X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: 4b73e23db244b54610b23d2dc4c190d11b2d8ec0 X-Git-Newrev: f1f79c5e822c884d7211d3a3b00f9ae43d0e8722 Message-Id: <20231212202335.1AF1F3857C58@sourceware.org> Date: Tue, 12 Dec 2023 20:23:35 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f1f79c5e822c884d7211d3a3b00f9ae43d0e8722 commit f1f79c5e822c884d7211d3a3b00f9ae43d0e8722 Author: Alexandre Oliva Date: Tue Dec 12 00:09:02 2023 -0300 arm: fix c23 0-named-args caller-side stdarg On arm-eabi targets, c23 stdarg execution tests that pass arguments to (...) functions (without any named argument), the caller passes everything on the stack, but the callee expects arguments in registers. My reading of the AAPCS32 suggests that the caller is correct, so I've arranged for the caller to pass the first arguments in registers to TYPE_NO_NAMED_STDARG_P-typed functions. The implementation issue in calls.cc is that n_named_args is initially set to zero in expand_call, so the test argpos < n_named_args yields false for all arguments, and aapcs_layout_arg takes !named as meaning stack. But there's a catch there: on targets in which neither strict_argument_naming nor !pretend_outgoing_varargs_named hold, n_named_args is bumped up to num_actuals, which covers stdarg arguments in pre-c23 cases, but not for TYPE_NO_NAMED_ARGS_STDARG_P. I'm hesitant to modify the generic ABI-affecting code, so I'm going for a more surgical fix for ARM AAPCS only. I suspect we might want yet another targetm predicate to enable the n_named_args overriding block to disregard TYPE_NO_NAMED_ARGS_STDARG_P, and allow all actuals to be passed as if named. for gcc/ChangeLog * config/arm/arm.h (CUMULATIVE_ARGS): Add aapcs_pretend_named. * config/arm/arm.cc (arm_init_cumulative_args): Set it for aapcs no-named-args stdarg functions. (aapcs_layout_arg): Ignore named if aapcs_pretend_named. Diff: --- gcc/config/arm/arm.cc | 9 +++++++-- gcc/config/arm/arm.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index 6e3e2e8fb1b..4a350bd8c8f 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -7019,8 +7019,11 @@ aapcs_layout_arg (CUMULATIVE_ARGS *pcum, machine_mode mode, pcum->aapcs_arg_processed = true; /* Special case: if named is false then we are handling an incoming - anonymous argument which is on the stack. */ - if (!named) + anonymous argument which is on the stack, unless + aapcs_pretend_named, in which case we're dealing with a + TYPE_NO_NAMED_ARGS_STDARG_P call and, even if args are !named, we + ought to use available registers first. */ + if (!named && !pcum->aapcs_pretend_named) return; /* Is this a potential co-processor register candidate? */ @@ -7141,6 +7144,8 @@ arm_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype, pcum->aapcs_arg_processed = false; pcum->aapcs_cprc_slot = -1; pcum->can_split = true; + pcum->aapcs_pretend_named = (fntype + && TYPE_NO_NAMED_ARGS_STDARG_P (fntype)); if (pcum->pcs_variant != ARM_PCS_AAPCS) { diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h index a9c2752c0ea..65d2d567686 100644 --- a/gcc/config/arm/arm.h +++ b/gcc/config/arm/arm.h @@ -1702,6 +1702,7 @@ typedef struct unsigned aapcs_vfp_reg_alloc; int aapcs_vfp_rcount; MACHMODE aapcs_vfp_rmode; + bool aapcs_pretend_named; /* Set for TYPE_NO_NAMED_ARGS_STDARG_P. */ } CUMULATIVE_ARGS; #endif