From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by sourceware.org (Postfix) with ESMTPS id 02C673858D28 for ; Mon, 4 Mar 2024 10:56:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02C673858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=foss.st.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 02C673858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709549770; cv=none; b=rUB16kvIAZptWpB0y7osLiQBFpjPXu/7gnEiAAB7N1w/pSu3XVgUqap5dx6V1eryznla7q+MS/ysD6QQlt+hJIYvR38EkjODok59YXUcfvVLEMrZUsmp+E+kcbLrWEjeEmaljoUB+ygSR9/xYuINBDw8qQ9fIs8EFaos3SDpZrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709549770; c=relaxed/simple; bh=BW8snq7XgCdt3tox7tM/L2X0jJc00+q/BT1dQpo8/xU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=plZPqH47dTv9ZDw8p/+mLfI50dVNcwgi68eukUZ2/6Eg0Pga9uSJWxjs+IuX2NhqJ9Mq5CmdgMlbXhSIol5jyf0JsYjHm7Hl2TbO6k60VjqJWqvMQlSkgldbkqoB+9XzAO0VpvcKU80WV1+CoR26DzcA4eNR0azS/NgfuesCD+I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 4247vtNM018266; Mon, 4 Mar 2024 11:56:05 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= selector1; bh=BjlYbYCT5BBYcPw6jKMHsNZ6qbdvphBUEv6dDIYE/vM=; b=6q am18JukLZIvnafvkp/bJSggOQaaJA6RrFDQ4af9bjZTAzx1d8lPFpTDHhpwVFZ7/ entEwWmaNOWClHOgkTgSOPuzI5Xi+jwFN+usdBjxoKCghri58vGvqUbjLfdVSuHk Lj8VzhP8HXM4UYMzPe1GQK3tjE2R4eT8IwIRYqxT+JhtKugMthD22NN3Hut2b5kl UPePU3tMynVb10v4Yy4PZy0Otq0nM+ZkGubiay47UVeutN8lJrafqrGhsgaSF+kp 5qhWvlxksejMzPiJuS+D01GJW0e73jw0rf4vnzogWNkYg4dcuo2ubtGZBfsM+sZG G1ZkK43E6x61ET0/9xzw== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3wkuvhf1w3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 Mar 2024 11:56:04 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 812E840046; Mon, 4 Mar 2024 11:55:59 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 0684626A986; Mon, 4 Mar 2024 11:55:38 +0100 (CET) Received: from [10.252.24.72] (10.252.24.72) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 4 Mar 2024 11:55:37 +0100 Message-ID: Date: Mon, 4 Mar 2024 11:55:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] arm: Fixed C23 call compatibility with arm-none-eabi To: "Richard Earnshaw (lists)" , CC: , , , Yvan ROUX References: <20240219091306.523967-1-torbjorn.svensson@foss.st.com> Content-Language: en-US From: Torbjorn SVENSSON In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.252.24.72] X-ClientProxiedBy: EQNCAS1NODE4.st.com (10.75.129.82) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-04_06,2024-03-04_01,2023-05-22_02 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_BLACK 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 2024-03-01 15:58, Richard Earnshaw (lists) wrote: > On 19/02/2024 09:13, Torbjörn SVENSSON wrote: >> Ok for trunk and releases/gcc-13? >> Regtested on top of 945cb8490cb for arm-none-eabi, without any regression. >> >> Backporting to releases/gcc-13 will change -std=c23 to -std=c2x. > > Jakub has just pushed a different fix for this, so I don't think we need this now. > > R. Would it still be benificial to have the 2 test cases for the AAPCS validation? Kind regards, Torbjörn > > >> >> -- >> >> In commit 4fe34cdcc80ac225b80670eabc38ac5e31ce8a5a, -std=c23 support was >> introduced to support functions without any named arguments. For >> arm-none-eabi, this is not as simple as placing all arguments on the >> stack. Align the caller to use r0, r1, r2 and r3 for arguments even for >> functions without any named arguments, as specified in the AAPCS. >> >> Verify that the generic test case have the arguments are in the right >> order and add ARM specific test cases. >> >> gcc/ChangeLog: >> >> * calls.h: Added the type of the function to function_arg_info. >> * calls.cc: Save the type of the function. >> * config/arm/arm.cc: Check in the AAPCS layout function if >> function has no named args. >> >> gcc/testsuite/ChangeLog: >> >> * gcc.dg/torture/c23-stdarg-split-1a.c: Detect out of order >> arguments. >> * gcc.dg/torture/c23-stdarg-split-1b.c: Likewise. >> * gcc.target/arm/aapcs/align_vaarg3.c: New test. >> * gcc.target/arm/aapcs/align_vaarg4.c: New test. >> >> Signed-off-by: Torbjörn SVENSSON >> Co-authored-by: Yvan ROUX >> --- >> gcc/calls.cc | 2 +- >> gcc/calls.h | 20 ++++++++-- >> gcc/config/arm/arm.cc | 13 ++++--- >> .../gcc.dg/torture/c23-stdarg-split-1a.c | 4 +- >> .../gcc.dg/torture/c23-stdarg-split-1b.c | 15 +++++--- >> .../gcc.target/arm/aapcs/align_vaarg3.c | 37 +++++++++++++++++++ >> .../gcc.target/arm/aapcs/align_vaarg4.c | 31 ++++++++++++++++ >> 7 files changed, 102 insertions(+), 20 deletions(-) >> create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg3.c >> create mode 100644 gcc/testsuite/gcc.target/arm/aapcs/align_vaarg4.c >> >> diff --git a/gcc/calls.cc b/gcc/calls.cc >> index 01f44734743..a1cc283b952 100644 >> --- a/gcc/calls.cc >> +++ b/gcc/calls.cc >> @@ -1376,7 +1376,7 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, >> with those made by function.cc. */ >> >> /* See if this argument should be passed by invisible reference. */ >> - function_arg_info arg (type, argpos < n_named_args); >> + function_arg_info arg (type, fntype, argpos < n_named_args); >> if (pass_by_reference (args_so_far_pnt, arg)) >> { >> const bool callee_copies >> diff --git a/gcc/calls.h b/gcc/calls.h >> index 464a4e34e33..88836559ebe 100644 >> --- a/gcc/calls.h >> +++ b/gcc/calls.h >> @@ -35,24 +35,33 @@ class function_arg_info >> { >> public: >> function_arg_info () >> - : type (NULL_TREE), mode (VOIDmode), named (false), >> + : type (NULL_TREE), fntype (NULL_TREE), mode (VOIDmode), named (false), >> pass_by_reference (false) >> {} >> >> /* Initialize an argument of mode MODE, either before or after promotion. */ >> function_arg_info (machine_mode mode, bool named) >> - : type (NULL_TREE), mode (mode), named (named), pass_by_reference (false) >> + : type (NULL_TREE), fntype (NULL_TREE), mode (mode), named (named), >> + pass_by_reference (false) >> {} >> >> /* Initialize an unpromoted argument of type TYPE. */ >> function_arg_info (tree type, bool named) >> - : type (type), mode (TYPE_MODE (type)), named (named), >> + : type (type), fntype (NULL_TREE), mode (TYPE_MODE (type)), named (named), >> pass_by_reference (false) >> {} >> >> + /* Initialize an unpromoted argument of type TYPE with a known function type >> + FNTYPE. */ >> + function_arg_info (tree type, tree fntype, bool named) >> + : type (type), fntype (fntype), mode (TYPE_MODE (type)), named (named), >> + pass_by_reference (false) >> + {} >> + >> /* Initialize an argument with explicit properties. */ >> function_arg_info (tree type, machine_mode mode, bool named) >> - : type (type), mode (mode), named (named), pass_by_reference (false) >> + : type (type), fntype (NULL_TREE), mode (mode), named (named), >> + pass_by_reference (false) >> {} >> >> /* Return true if the gimple-level type is an aggregate. */ >> @@ -96,6 +105,9 @@ public: >> libgcc support functions). */ >> tree type; >> >> + /* The type of the function that has this argument, or null if not known. */ >> + tree fntype; >> + >> /* The mode of the argument. Depending on context, this might be >> the mode of the argument type or the mode after promotion. */ >> machine_mode mode; >> diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc >> index 1cd69268ee9..98e149e5b7e 100644 >> --- a/gcc/config/arm/arm.cc >> +++ b/gcc/config/arm/arm.cc >> @@ -7006,7 +7006,7 @@ aapcs_libcall_value (machine_mode mode) >> numbers referred to here are those in the AAPCS. */ >> static void >> aapcs_layout_arg (CUMULATIVE_ARGS *pcum, machine_mode mode, >> - const_tree type, bool named) >> + const_tree type, bool named, const_tree fntype) >> { >> int nregs, nregs2; >> int ncrn; >> @@ -7018,8 +7018,9 @@ 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 the function has no named >> + arguments (functions without named arguments was introduced in C23). */ >> + if ((fntype == NULL_TREE || !TYPE_NO_NAMED_ARGS_STDARG_P (fntype)) && !named) >> return; >> >> /* Is this a potential co-processor register candidate? */ >> @@ -7267,7 +7268,7 @@ arm_function_arg (cumulative_args_t pcum_v, const function_arg_info &arg) >> >> if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) >> { >> - aapcs_layout_arg (pcum, arg.mode, arg.type, arg.named); >> + aapcs_layout_arg (pcum, arg.mode, arg.type, arg.named, arg.fntype); >> return pcum->aapcs_reg; >> } >> >> @@ -7342,7 +7343,7 @@ arm_arg_partial_bytes (cumulative_args_t pcum_v, const function_arg_info &arg) >> >> if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) >> { >> - aapcs_layout_arg (pcum, arg.mode, arg.type, arg.named); >> + aapcs_layout_arg (pcum, arg.mode, arg.type, arg.named, arg.fntype); >> return pcum->aapcs_partial; >> } >> >> @@ -7367,7 +7368,7 @@ arm_function_arg_advance (cumulative_args_t pcum_v, >> >> if (pcum->pcs_variant <= ARM_PCS_AAPCS_LOCAL) >> { >> - aapcs_layout_arg (pcum, arg.mode, arg.type, arg.named); >> + aapcs_layout_arg (pcum, arg.mode, arg.type, arg.named, arg.fntype); >> >> if (pcum->aapcs_cprc_slot >= 0) >> { >> diff --git a/gcc/testsuite/gcc.dg/torture/c23-stdarg-split-1a.c b/gcc/testsuite/gcc.dg/torture/c23-stdarg-split-1a.c >> index 2dff79235b2..717fc4bfd07 100644 >> --- a/gcc/testsuite/gcc.dg/torture/c23-stdarg-split-1a.c >> +++ b/gcc/testsuite/gcc.dg/torture/c23-stdarg-split-1a.c >> @@ -5,7 +5,6 @@ >> /* { dg-options "-std=c23 -pedantic-errors" } */ >> /* { dg-additional-sources "c23-stdarg-split-1b.c" } */ >> >> -extern void abort (void); >> extern void exit (int); >> >> double f (...); >> @@ -22,8 +21,7 @@ void h7 (volatile struct s x, ...); >> int >> main () >> { >> - if (f (1, 2.0, 3, 4.0) != 10.0) >> - abort (); >> + f (1, 2.0, 3, 4.0); >> g (0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); >> g (0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f); >> h1 (0, 0.0, 1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9); >> diff --git a/gcc/testsuite/gcc.dg/torture/c23-stdarg-split-1b.c b/gcc/testsuite/gcc.dg/torture/c23-stdarg-split-1b.c >> index 064da121ec2..3b70fe1595a 100644 >> --- a/gcc/testsuite/gcc.dg/torture/c23-stdarg-split-1b.c >> +++ b/gcc/testsuite/gcc.dg/torture/c23-stdarg-split-1b.c >> @@ -8,17 +8,20 @@ >> >> extern void abort (void); >> >> -double >> +void >> f (...) >> { >> va_list ap; >> va_start (ap); >> - double ret = va_arg (ap, int); >> - ret += va_arg (ap, double); >> - ret += va_arg (ap, int); >> - ret += va_arg (ap, double); >> + if (va_arg (ap, int) != 1) >> + abort(); >> + if (va_arg (ap, double) != 2) >> + abort(); >> + if (va_arg (ap, int) != 3) >> + abort(); >> + if (va_arg (ap, double) != 4) >> + abort(); >> va_end (ap); >> - return ret; >> } >> >> void >> diff --git a/gcc/testsuite/gcc.target/arm/aapcs/align_vaarg3.c b/gcc/testsuite/gcc.target/arm/aapcs/align_vaarg3.c >> new file mode 100644 >> index 00000000000..23cc78d5230 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/arm/aapcs/align_vaarg3.c >> @@ -0,0 +1,37 @@ >> +/* Test AAPCS layout (alignment of varargs) for callee. */ >> + >> +/* { dg-do run { target arm_eabi } } */ >> +/* { dg-require-effective-target arm32 } */ >> +/* { dg-options "-std=c23 -O2 -fno-inline" } */ >> + >> +#include >> + >> +extern void abort (void); >> + >> +typedef __attribute__((aligned (8))) int alignedint; >> + >> +void >> +foo (...) >> +{ >> + int i = 0; >> + va_list va; >> + va_start (va); >> + /* Arguments should be passed in the same registers as if they were ints. */ >> + for (i = 5; i >= 0; i--) >> + if (va_arg (va, int) != i) >> + abort (); >> + va_end (va); >> +} >> + >> +int >> +main (int argc, char **argv) >> +{ >> + alignedint a = 5; >> + alignedint b = 4; >> + alignedint c = 3; >> + alignedint d = 2; >> + alignedint e = 1; >> + alignedint f = 0; >> + foo (a, b, c, d, e, f); >> + return 0; >> +} >> diff --git a/gcc/testsuite/gcc.target/arm/aapcs/align_vaarg4.c b/gcc/testsuite/gcc.target/arm/aapcs/align_vaarg4.c >> new file mode 100644 >> index 00000000000..c4333f33677 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/arm/aapcs/align_vaarg4.c >> @@ -0,0 +1,31 @@ >> +/* Test AAPCS layout (alignment of varargs) for callee. */ >> + >> +/* { dg-do run { target arm_eabi } } */ >> +/* { dg-require-effective-target arm32 } */ >> +/* { dg-options "-std=c23 -O2 -fno-inline" } */ >> + >> +#include >> + >> +extern void abort (void); >> + >> +typedef __attribute__((aligned (8))) int alignedint; >> + >> +void >> +foo (...) >> +{ >> + int i = 0; >> + va_list va; >> + va_start (va); >> + /* alignedint should be pulled out of regs/stack just like an int. */ >> + for (i = 5; i >= 0; i--) >> + if (va_arg (va, alignedint) != i) >> + abort (); >> + va_end (va); >> +} >> + >> +int >> +main (int argc, char **argv) >> +{ >> + foo (5, 4, 3, 2, 1, 0); >> + return 0; >> +} >