From patchwork Thu Jun 13 13:33:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 1947398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=EwsHReST; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W0Nhb4txHz1ydW for ; Thu, 13 Jun 2024 23:35:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E7CF3882053 for ; Thu, 13 Jun 2024 13:35:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id D962F3882059 for ; Thu, 13 Jun 2024 13:33:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D962F3882059 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 D962F3882059 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::336 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718285637; cv=none; b=N7i+lg+kHbhgEfqfnbXuDFuvx1r5Z3sIgApBrP75vH0R6iiAPMJYF17f+kqb6z825LZ17NSe2dyoMHyd1HaSs/ab5q790ODQyLyboqyIKECyMTfBksAQzINm/XDYABLLIAq6XEFqCtclIDBkIvRDkKs711U6UizR8vmM/oNX0FE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718285637; c=relaxed/simple; bh=bx28NPk73RbjnUyKbbWMA8m8jDxWKcRfS4lIeecQAqo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tfvDZYVqZv5ac/iwmn+V+x7L4hTi/MiIzhz/lPpKdlz7w5GUVfQ27xlewbMAhtx1U+frt17NFqMbOsl/obIA50TC3Sdfpd9QkjtxGvPXFM4dbcFi1UyWtdeYcVtH7kBTH1qfsvT4M0Q23sps9gwNjfmhuQ2RDRHTvL3xZGHGKus= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-42179dafd6bso13666905e9.0 for ; Thu, 13 Jun 2024 06:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1718285633; x=1718890433; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cn5nB523Xnz3IBPtCIQt3VVQKFitLD8KkxG6XDKiq0o=; b=EwsHReSTeVCfZrXLejkDFVEFlWUZqo0DKV5X6hUt9CziagdPGCN8JU+eKncakQ7QET H+nLLsyDMBLCJphA5ObmcE9Ftq3lbTEavu0G9vzmsL2EmlY6OKO3yFKDEi1PFJb8Bop1 jZ97jFYsQeau40k+P0Lo5RuaFybQQ0geMXDTYVwJ6kZ5yWM+KhEEPeqUCuJQ7bY0Ld/u teIagpPtf68fcQWPadfeLeb8++p6un/nRRLzo/gCfG9o/mt0iRlyhJKm17iTpCN4MBJK nHx24RaizRrsF3ga0oSY/sJDbyEgbFHkmAcWp5i0SDuJ+8AfsANoZr5xVxRkvxyxZjEN Llyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718285633; x=1718890433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cn5nB523Xnz3IBPtCIQt3VVQKFitLD8KkxG6XDKiq0o=; b=tc7GeeK47ardzNZFP3cQAwpDS3qpyqxCdv1w7tyJt+0o4eaOckkWTOShr4lkl81V0c pcEQg4RoeLLLjrDEy+EqhmUFgbrYU107QqU8zaSR2RXNw/mclWrCBkT/xxyDxJp6Ir0Y 2aH82laSh56wsXtrO/bbtuywWmi/qfA1mDvWtnciqkDS3F2j6njqQKDI6MuV5UG7UgqZ XjK479UAluoseBQwbNZGvXRgf05ZF3G2Ie98lydyJPxzeRBAfc/GonXrUWredkrbnp0m L5locVnWmBCHJVSvSisH4kNaKC+9x80FYm7Gp7/E9pDy/07yHHjcxNSjfzcJgf9dDkhS /Vog== X-Gm-Message-State: AOJu0YyhvoLCIEfR8T2SDZLAf7dfWo/LDKM4XHJntG2mGIfM764MeZOr U94lqocAs+narPy5UXd4U1K2Bk7orOqsNFCqmOI+F48Kz2X4450sZNEy5izoZt45RBnzZHKvtVQ = X-Google-Smtp-Source: AGHT+IG5QlyBPRbIMiKe0K/bdN75lO6GtqMq4WoC6ojtnDsq+g4D7qf2BGep5EeJrOXA/AQukpbmMg== X-Received: by 2002:a05:600c:3512:b0:422:fdb:efb3 with SMTP id 5b1f17b1804b1-422b6fc46e1mr24128435e9.12.1718285633555; Thu, 13 Jun 2024 06:33:53 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422870e9145sm62391955e9.22.2024.06.13.06.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:33:53 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED 05/30] ada: Missing support for 'Old with overloaded function Date: Thu, 13 Jun 2024 15:33:11 +0200 Message-ID: <20240613133338.1809385-5-poulhies@adacore.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240613133338.1809385-1-poulhies@adacore.com> References: <20240613133338.1809385-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Javier Miranda The compiler reports an error when the prefix of 'Old is a call to an overloaded function that has no parameters. gcc/ada/ * sem_attr.adb (Analyze_Attribute): Enhance support for using 'Old with a prefix that references an overloaded function that has no parameters; add missing support for the use of 'Old within qualified expressions. * sem_util.ads (Preanalyze_And_Resolve_Without_Errors): New subprogram. * sem_util.adb (Preanalyze_And_Resolve_Without_Errors): New subprogram. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_attr.adb | 37 ++++++++++++++++++++++++++++++++++++- gcc/ada/sem_util.adb | 12 ++++++++++++ gcc/ada/sem_util.ads | 3 +++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index 2fd95f36d65..22fbca45ac5 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -5534,7 +5534,42 @@ package body Sem_Attr is -- The prefix must be preanalyzed as the full analysis will take -- place during expansion. - Preanalyze_And_Resolve (P); + -- If the attribute reference has an expected type or shall resolve + -- to a given type, the same applies to the prefix; otherwise the + -- prefix shall be resolved independently of context (RM 6.1.1(8/5)). + + if Nkind (Parent (N)) = N_Qualified_Expression then + Preanalyze_And_Resolve (P, Etype (Parent (N))); + + -- An special case occurs when the prefix is an overloaded function + -- call without formals; in order to identify such case we preanalyze + -- a duplicate of the prefix ignoring errors. + + else + declare + P_Copy : constant Node_Id := New_Copy_Tree (P); + + begin + Set_Parent (P_Copy, Parent (P)); + + Preanalyze_And_Resolve_Without_Errors (P_Copy); + + -- In the special case of a call to an overloaded function + -- without extra formals we resolve it using its returned + -- type (which is the unique valid call); if this not the + -- case we will report the error later, as part of the + -- regular analysis of the full expression. + + if Nkind (P_Copy) = N_Function_Call + and then Is_Overloaded (Name (P_Copy)) + and then No (First_Formal (Entity (Name (P_Copy)))) + then + Preanalyze_And_Resolve (P, Etype (Name (P_Copy))); + else + Preanalyze_And_Resolve (P); + end if; + end; + end if; -- Ensure that the prefix does not contain attributes 'Old or 'Result diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 5bea088c44e..438dea79977 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -25790,6 +25790,18 @@ package body Sem_Util is return Kind; end Policy_In_Effect; + ------------------------------------------- + -- Preanalyze_And_Resolve_Without_Errors -- + ------------------------------------------- + + procedure Preanalyze_And_Resolve_Without_Errors (N : Node_Id) is + Status : constant Boolean := Get_Ignore_Errors; + begin + Set_Ignore_Errors (True); + Preanalyze_And_Resolve (N); + Set_Ignore_Errors (Status); + end Preanalyze_And_Resolve_Without_Errors; + ------------------------------- -- Preanalyze_Without_Errors -- ------------------------------- diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index f282d1fad99..bda295f0a7f 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -3388,6 +3388,9 @@ package Sem_Util is function Yields_Universal_Type (N : Node_Id) return Boolean; -- Determine whether unanalyzed node N yields a universal type + procedure Preanalyze_And_Resolve_Without_Errors (N : Node_Id); + -- Preanalyze and resolve N without reporting errors + procedure Preanalyze_Without_Errors (N : Node_Id); -- Preanalyze N without reporting errors