From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by sourceware.org (Postfix) with ESMTPS id 41E3D385828A for ; Sun, 19 Nov 2023 07:32:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41E3D385828A 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 41E3D385828A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b36 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700379137; cv=none; b=kARpw+W1cndcPHmVLQ0IrijJJvNSI6xitf6kILSM5I+plGg0FQ6JmrfawvHT5aziPmvZqi9ljbYTSXJT8/jkOFbKA+FIGLhuxszGgz8Nkckhm/9BlrW7lNAfRWUqgMjLd9VLomHV7xuGDjXIJLxr0wNQvfAOWBzL0rFcsfUQMfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700379137; c=relaxed/simple; bh=5ndFcZ3hP/OVGKWvydXXyh3OECwYRDZjDdl3pN3iUfQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QViJyatGSf3f3eGbs/exAcKSqfAK0FQSPMcSoPnh27TMLk1MENf8nGTelVQYrWxg9NvyxomHma1h9cXdcFOyO5JKKSBGgV/41koYqyfaOlFHUKnv5IBXu8eZX07nIeYpQ8SsyOwKKljfx0qDVEJ8NwHjftR43LwmLbq7MBNEW2c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-d9caf5cc948so3220463276.0 for ; Sat, 18 Nov 2023 23:32:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1700379135; x=1700983935; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=tHIr9T7A9+AB44v3X66vz3nBl4C09+NAcVr6/FcuTzQ=; b=cM8g00SFkemuVfP08jegSqk+xiQ4C7QiHVobIlc1XGdD9AoEKucbU+nfL4Vbmg1KY5 RrNMllQzqpxYqX50Sg+HaoUuM4aIYdYYLiSCLgC5Fym4HRaDdSuKQ25v9cY/nb/9Gk+P jDw6ErBDU9PgDQATeqiUgo41Pc7c/LBYRWPhAridLc5/5Jrv9NKrdCCWk8pVn5Ag7hY2 zADuE002HYRn6U4fJVzou5Y6pFPTWf9VmvWQu09RXTJ+vaosHAdHz4jPSTMAX+h/CSRO fgPi6SkhtHV7DuQQ5DscF6ucFc/CsvyCh+J+RW54k7xOfLb17ZtH9dMDFxdKce8O09xV U15A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700379135; x=1700983935; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tHIr9T7A9+AB44v3X66vz3nBl4C09+NAcVr6/FcuTzQ=; b=MN8WSxCSZ6cTlZQVbLo5ybU2ye3tu07BPbfo6fUcqbi/wIrOrDT25PtmXJvtI1rvRU lxvWUij5SNNGmDxiShWYRwXAvrr8yrqPjMLRMbD3Vq/41BKHRhcErZbxCnlA3hvN3nU/ 1hTkqa1/iL9CpSTe6eIjTn7Ih0txLs70a3Nw0JLduIIK8EBiKgswJSPT5gTrc4guNpPM YZh65acqDygVgjzIh3kptiEKaAMxMXjmXTnHjvMwhF2oUnJuJgwDyPqOLYfc6HVTl2a0 ZPSUEyRnv7jDeX7xUq61fuxAabKWan5rbmWroK7CwojCtjkuyu178tTF65yNIg1B9YVI bCJg== X-Gm-Message-State: AOJu0YwFkdK1sYyUVGLhANExPaBl3RPasv1lguUecDrOPsepjs5LEdRq bZA5iaBYU/t3GlADc6PEFpOugRC3N9/p3v1YxCCicw== X-Google-Smtp-Source: AGHT+IEgh0zH7rdJc6xCGbfa+XzDZ9LE3EhMSPf+/+GZEjmdmcZ8m9W7iM5o+YWlsjHGxid66suV0w== X-Received: by 2002:a25:81d0:0:b0:d9c:aa17:2ae3 with SMTP id n16-20020a2581d0000000b00d9caa172ae3mr3444738ybm.64.1700379135499; Sat, 18 Nov 2023 23:32:15 -0800 (PST) Received: from free.home ([2804:7f1:2080:51b3:d545:cbee:40c0:c7a7]) by smtp.gmail.com with ESMTPSA id o5-20020a056a0015c500b006bb5ff51177sm3930666pfu.194.2023.11.18.23.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 23:32:15 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3AJ7W2TD121751 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 19 Nov 2023 04:32:03 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: Joseph Myers , Nick Clifton , Richard Earnshaw , Ramana Radhakrishnan , Kyrylo Tkachov Subject: [PATCH] arm: fix c23 0-named-args caller-side stdarg Organization: Free thinker, does not speak for AdaCore Date: 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=-12.3 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 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. Regstrapped on x86_64-linux-gnu, also tested on arm-eabi with default cpu on trunk, and with tms570 on gcc-13. Ok to install? 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 | 4 +++- gcc/config/arm/arm.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index 25a1ad736ad96..c31bf193365ef 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -7011,7 +7011,7 @@ aapcs_layout_arg (CUMULATIVE_ARGS *pcum, machine_mode mode, /* Special case: if named is false then we are handling an incoming anonymous argument which is on the stack. */ - if (!named) + if (!named && !pcum->aapcs_pretend_named) return; /* Is this a potential co-processor register candidate? */ @@ -7132,6 +7132,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