From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 244093832345 for ; Mon, 14 Nov 2022 13:52:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 244093832345 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x32a.google.com with SMTP id j5-20020a05600c410500b003cfa9c0ea76so7951029wmi.3 for ; Mon, 14 Nov 2022 05:52:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3bc6/6QwWlM7oXY/pLQumjpRnpPYnUrjz7pmXO9eYI4=; b=g0o+AIa9y7bWIeRROYAJnHLehhMRfO7F7pIXn7QVhyJIKGGR3Ht0ddNtey8pVs7GOk 7Av2F6TyjIP0y7eUDpNNfLWlYGc2UCB4Apo4R8EF0or4u7j8HQTi23kEdqI2TYDkmUCm +tPP4kiK1n6AejWb0b0zhKw8TQ2tEMcZrmC3LUIOKiPeNDukh1uogixnG+WovC9mWX73 QXTA+8negxNz0jH3plFO3ZlLf8KmRTyldj8Q2bG7ODUK2sdTPJgLRkekpDVZ/bzit4gF qCaCKKtAl5dMUydRhPyX08Ihqx0blO3Aud3SjfyvcpXcId2dVqEIyJZ6fDpvVSf5L60G chrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3bc6/6QwWlM7oXY/pLQumjpRnpPYnUrjz7pmXO9eYI4=; b=hB0jk1YJDtFK0AXLHWC0YPnwx7Qtibqt5wlr1+5saf+JcZaPpxDI/5aTcq3y8kag+s OTi3/V/Wsu5F6YQw/434v3yDpdaHFAt4+Bdvt/Vo1g7EiC8MgP/YpyHV6Gu1XiVktqqM kkWvqNcTSIMKC3K/V8PnwnKISg4NG2Hk/x7cfHO/4mwW+JzM39QpDZ5QObfJgrrm3LOs /zFk832CnCW7DBymZVUI/YNZz58Rpqm8HgwU8R88Ow8nuNs83CdqsB3DmjmadarAKZ+d X2YNMb8OpSi1B6noRUCLIU/XDPbajhRW0+/5kXCjtuWjhr3lbvrPhan2J9PAloyuUOOo U9lg== X-Gm-Message-State: ANoB5ploCFjn0aCDuy4xynLaj6wJnIhLHFQKzxvb1WnCxkeTwP3/qVOK eCElF5uhSrU8lwuKDnN4JmJ0D4GfnN3mgA== X-Google-Smtp-Source: AA0mqf4ZQ0j4JODw0eqGM37BEd1Sn54fvM6PYpYQtd4tK/220RvZIGuuQrhVicTRenVsuEDJPLmUcA== X-Received: by 2002:a05:600c:220c:b0:3cf:7fb1:e217 with SMTP id z12-20020a05600c220c00b003cf7fb1e217mr8070705wml.92.1668433934933; Mon, 14 Nov 2022 05:52:14 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id m14-20020a05600c4f4e00b003a1980d55c4sm20485484wmq.47.2022.11.14.05.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 05:52:14 -0800 (PST) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Adjust locations in aspects on generic formal subprograms Date: Mon, 14 Nov 2022 14:52:12 +0100 Message-Id: <20221114135212.52840-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.4 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 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: From: Piotr Trojanek 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. Tested on x86_64-pc-linux-gnu, committed on master. --- 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; -- 2.34.1