From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id D26F03858289 for ; Wed, 6 Dec 2023 02:28:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D26F03858289 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D26F03858289 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701829684; cv=none; b=iKSY0Y8KtQCfoZ4FDCtVyfJgBGxp+KuUU+yYlCowV6ZcLg4xyuIoV1HAbhCPRV+G9IPXcWdDQx03DQTDKrGNjCKL98ZGV95AQoJSyZIKtmbRijpJG0zxJn19BHAmpHHSZsvW8m/eDxMKXdM30TQtIw7LJDmoD2iDjJci07nW40k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701829684; c=relaxed/simple; bh=IbgjJ5OWjHpItIUSClbxvSLU4Ru05Jr1VG35iKfckos=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=H1gTShqCST2oy5RN93PNumZi8gNnLhH9T69+1LeKJ9odw3BVrvQhTBdSfWs2cwTQ54orCWjHhJrqH9cEmz8OHvyH1KHASvszJwLMfiQ9JZT0YN6/+DXt1V+i8pHtQ3Gu2UKiAFPlsxH+BCAQfNqlydzO18e+32ht7ky+RX5Hp4U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6cb55001124so333699b3a.0 for ; Tue, 05 Dec 2023 18:28:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1701829681; x=1702434481; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Xu/fxlc6bRIMqubI8I11OvB+Rd9q1JbjDVV+JRQATEw=; b=MPFjR9L9dVtL/acEn5fZzJTL3j7BPg3OOUbRftshMBOhkdSyMTfZbDgmxMj2NkdN3L LWkDZyJiZ2njJrgbPZ+GS/7dJX0QgzuP/W/RX+xzfcUSKc3lfexK5xbXpW30/p5zgk04 mtimNvfoklSO8CA7bjmJRDV6ww5JrhATw/U03yALDTG3x+u2tuFOis6zbUh25v00k92E T9/E6aHUuaAM52zx8I87nCWiFsokyXCMf8pxQEtRWh80v23g3PH6BLjeNlo0+VpusIOT Y3oaUqyTvXEg9sHqaMf3S/S6v+YmUpv2OuqvV4hOP8JZpb4mcC505/s4/6er98XSC8mq xydw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701829681; x=1702434481; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xu/fxlc6bRIMqubI8I11OvB+Rd9q1JbjDVV+JRQATEw=; b=gsbl6YcPrYwT8qCL8R5ySHC/fasHxlXf7UH2Cybg08bHKFHUTzbbUc3GlFNO8JnIlS 5Qzm+sbbcZN6+5EDCK+D1IbHAcN2lTIsX8ayGqHkGIs1/IPjcEnzL2HQvGTy6kRcSId1 EdzMF8lp9+/YXreoFg3IEpllxMtrQGwokt3FQVuXUKyRixeINSmfwsZ3TTjkYtySviYq Kkg0AKH0EBOn9ERw2KbzMhiVPTdPu9fLEiRObPlw/KX1HQOTiwpYNLLuBR4NbE14NFUs 2boLa8h8j0glsHSwerW2ZvLs+MMy89GRrBxfH/jOpJHBCoROZHF0ctfo3C/xXcuvBb6G R2gg== X-Gm-Message-State: AOJu0YzUzx0fA3IITKwfAbMvZtQjRs3NRnM3VY3HCKskvHGHk+X5Y40b Gq5LFFj4s5ajMrgeAhT/5aISFjmDG2fZALF1pJJ52w== X-Google-Smtp-Source: AGHT+IF9TBO51NUbyOsB0Gsp3KYPAYRQLZaihWXBz2X0JBgzmpIRn+2vvwh0H+Ysd+2+v1MrgP6rGg== X-Received: by 2002:a05:6a20:da9e:b0:18b:3401:5c56 with SMTP id iy30-20020a056a20da9e00b0018b34015c56mr313612pzb.22.1701829680979; Tue, 05 Dec 2023 18:28:00 -0800 (PST) Received: from free.home ([2804:7f1:2080:ac51:aa28:dd55:15e9:45df]) by smtp.gmail.com with ESMTPSA id s24-20020a62e718000000b006ce6b0d76d1sm2117343pfh.69.2023.12.05.18.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 18:28:00 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3B62RnBl234747 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Dec 2023 23:27:49 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: Joseph Myers , Nick Clifton , Richard Earnshaw , Ramana Radhakrishnan , Kyrylo Tkachov Subject: Re: [PATCH] arm: fix c23 0-named-args caller-side stdarg Organization: Free thinker, does not speak for AdaCore References: Date: Tue, 05 Dec 2023 23:27:49 -0300 In-Reply-To: (Alexandre Oliva's message of "Sun, 19 Nov 2023 04:32:02 -0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_QUOTING autolearn=ham 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 Nov 19, 2023, Alexandre Oliva wrote: > 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. Ping? This slightly modified patch only adds comments to aapcs_layout_arg compared with the original one. The commit message doesn't name explicitly the fixed testsuite failures. Here they are: FAIL: gcc.dg/c23-stdarg-4.c execution test FAIL: gcc.dg/torture/c23-stdarg-split-1a.c -O0 execution test FAIL: gcc.dg/torture/c23-stdarg-split-1a.c -O1 execution test FAIL: gcc.dg/torture/c23-stdarg-split-1a.c -O2 execution test FAIL: gcc.dg/torture/c23-stdarg-split-1a.c -O2 -flto -fno-use-linker-plugin -flto-partition=none execution test FAIL: gcc.dg/torture/c23-stdarg-split-1a.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects execution test FAIL: gcc.dg/torture/c23-stdarg-split-1a.c -O3 -g execution test FAIL: gcc.dg/torture/c23-stdarg-split-1a.c -Os execution test Tested on arm-eabi. Ok to install? 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. --- 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 6e3e2e8fb1bfb..4a350bd8c8f47 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 a9c2752c0ea5e..65d2d567686d3 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 -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer More tolerance and less prejudice are key for inclusion and diversity Excluding neuro-others for not behaving ""normal"" is *not* inclusive