From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 7BEAC3858C60; Mon, 14 Nov 2022 13:51:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BEAC3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668433888; bh=Zt7R3t8iYEBwbm0f45OwLjINv08zsypUi0GhFxKx5+M=; h=From:To:Subject:Date:From; b=qmgfjxMG1z1wA01AQxEIIYEcKftfr7vC4YhcSEtbZncptevMhwyn0IQTPVe6MEVlA AYDPoygRZXYUqJlO/zkz+IE9BQC62av6P4zh9FC3u3Rnq/2HUIaAQHaUhkMBBM8VYI XIzZfZrUvGNRUH4W30efVZAuszVdRzfB1WQx1B5s= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4010] ada: Adjust locations in aspects on generic formal subprograms X-Act-Checkin: gcc X-Git-Author: Piotr Trojanek X-Git-Refname: refs/heads/master X-Git-Oldrev: 35f29cfe9f6e48dc570d4cd61b906c3cbb2e227a X-Git-Newrev: 28e5c45bd519aa363cba1eec4d215b173c360cab Message-Id: <20221114135128.7BEAC3858C60@sourceware.org> Date: Mon, 14 Nov 2022 13:51:28 +0000 (GMT) List-Id: https://gcc.gnu.org/g:28e5c45bd519aa363cba1eec4d215b173c360cab commit r13-4010-g28e5c45bd519aa363cba1eec4d215b173c360cab Author: Piotr Trojanek Date: Fri Oct 28 22:15:53 2022 +0200 ada: Adjust locations in aspects on generic formal subprograms When instantiating a generic that has formal subprogram parameter with contracts, e.g.: generic with procedure P with Pre => ..., Post => ...; ... we create a wrapper that executes Pre/Post contracts before/after calling the actual subprogram. Errors emitted for these contracts will now have locations of the instance and not just of the generic. gcc/ada/ * sem_ch12.adb (Build_Subprogram_Wrappers): Adjust slocs of the copied aspects, just like we do in Build_Class_Wide_Expression for inherited class-wide contracts. Diff: --- gcc/ada/sem_ch12.adb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index 03ce5d51a03..72c2eef7061 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -1203,12 +1203,31 @@ package body Sem_Ch12 is ------------------------------- procedure Build_Subprogram_Wrappers is + function Adjust_Aspect_Sloc (N : Node_Id) return Traverse_Result; + -- Adjust sloc so that errors located at N will be reported with + -- information about the instance and not just about the generic. + + ------------------------ + -- Adjust_Aspect_Sloc -- + ------------------------ + + function Adjust_Aspect_Sloc (N : Node_Id) return Traverse_Result is + begin + Adjust_Instantiation_Sloc (N, S_Adjustment); + return OK; + end Adjust_Aspect_Sloc; + + procedure Adjust_Aspect_Slocs is new + Traverse_Proc (Adjust_Aspect_Sloc); + Formal : constant Entity_Id := Defining_Unit_Name (Specification (Analyzed_Formal)); Aspect_Spec : Node_Id; Decl_Node : Node_Id; Actual_Name : Node_Id; + -- Start of processing for Build_Subprogram_Wrappers + begin -- Create declaration for wrapper subprogram -- The actual can be overloaded, in which case it will be @@ -1247,6 +1266,7 @@ package body Sem_Ch12 is Aspect_Spec := First (Aspect_Specifications (Decl_Node)); while Present (Aspect_Spec) loop + Adjust_Aspect_Slocs (Aspect_Spec); Set_Analyzed (Aspect_Spec, False); Next (Aspect_Spec); end loop;