From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id B82B0385C6E4 for ; Tue, 18 Jul 2023 13:13:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B82B0385C6E4 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-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4fbc0314a7bso9264333e87.2 for ; Tue, 18 Jul 2023 06:13:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1689686023; x=1690290823; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=spdKvDJzlaTLX6bhG48cSOI6Lgef+m81KX+Myu35kLs=; b=N0dVrhL9xQ3Hdqwj18l9EQl7obL7Qrb2gYjrvneAMR0PqUOQjTG+NEaK66l/ebEcr/ lEywjklQA7UG73FWdl7IT4mnLoc2GLZcGXd0DoJ/Y8s59e5OcY3Sf49NDvA0/wS782fO J3R0ytBMI8kn1mXYdQDgz5JY6f97J/qqNXGfB/BG5/2boJd+XMtTdzUpqK1fiH2o6/xJ E/+zvQA0Z/SwXA3/m1PPw6aci5ioOTZLDFzYFWU75vnJ2PAuTDfHk2gjPLPR6vPoUZMk JFSqLU/BzxLGp5+2iqTH1uwVrtQcn8qZrOvO/NKahf2cbmkxCSXibtu9lyzKe4wtaTl0 aPsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689686023; x=1690290823; 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=spdKvDJzlaTLX6bhG48cSOI6Lgef+m81KX+Myu35kLs=; b=OoBsaah8DMBVqZcpVFMbOUiQU5Qfy+WSrEu8Vfc3Prc8Gr0WGAUBWAZWWOWPorDP2m mN7LGK75IcfWh0HSs474l62fA121gbRcj/qABofGyN3+kOipsDYfL1VUaMPNWMMbP4j6 k1kLbyR6L1SBEAX96GsIu14oQHHLsD0uM+K9EC36QIHxmjPATfAh+tUJD4sjoATO9TYU GecDX9wPucq9h03EFQEE3yemZUazN0nKVIwacTcTRdAdSpoeUJVvHFbVervpeVhuFqn9 RgeBEsi7gEAvxFGkouPD32rBWd919YzNY1SXByaNbPkgb0Xs881cAthlckEGVmhyqr5/ a+8w== X-Gm-Message-State: ABy/qLaXAj+J+X9H0VC4WeVlzeOxLJ3eMB5NRNKhtQQgdllLsExUNsF5 eiF1hX/NR5HpWsPE9sB1nYQVkMXeBWUwgQmOmLfUZQ== X-Google-Smtp-Source: APBJJlGHEM9QuUvvU8DjejlPlzstucxZN6GB4Htpx+l8h7TFXm+ZvZdiqZBkT0VOfQFsdw5kHR6HEQ== X-Received: by 2002:a19:2d17:0:b0:4fb:8948:2b2b with SMTP id k23-20020a192d17000000b004fb89482b2bmr8673363lfj.48.1689686023229; Tue, 18 Jul 2023 06:13:43 -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 f22-20020a7bc8d6000000b003fbb5142c4bsm10452405wml.18.2023.07.18.06.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 06:13:42 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Viljar Indus Subject: [COMMITTED] ada: Avoid iterator conflicts in container aggregates Date: Tue, 18 Jul 2023 15:13:42 +0200 Message-Id: <20230718131342.81513-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.7 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 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: Viljar Indus Create temporary scope for the iterators defined in a container aggregate so that it would not be put to the same scope where the expression was used. This would otherwise lead to multiple aggregates with iterators that have the same name leading to a name conflict. gcc/ada/ * sem_aggr.adb (Resolve_Iterated_Association): Add temporary scope when analyzing the Iterator Specification. Use preanalysis instead of Analysis to avoid polluting the tree. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_aggr.adb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb index ecd508a66f8..364217d03db 100644 --- a/gcc/ada/sem_aggr.adb +++ b/gcc/ada/sem_aggr.adb @@ -3231,11 +3231,24 @@ package body Sem_Aggr is Typ := Key_Type; elsif Present (Iterator_Specification (Comp)) then + -- Create a temporary scope to avoid some modifications from + -- escaping the Analyze call below. The original Tree will be + -- reanalyzed later. + + Ent := New_Internal_Entity + (E_Loop, Current_Scope, Sloc (Comp), 'L'); + Set_Etype (Ent, Standard_Void_Type); + Set_Parent (Ent, Parent (Comp)); + Push_Scope (Ent); + Copy := Copy_Separate_Tree (Iterator_Specification (Comp)); Id_Name := Chars (Defining_Identifier (Iterator_Specification (Comp))); - Analyze (Copy); + Preanalyze (Copy); + + End_Scope; + Typ := Etype (Defining_Identifier (Copy)); else -- 2.40.0