From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id A2F293858291 for ; Fri, 4 Nov 2022 13:57:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A2F293858291 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-wr1-x434.google.com with SMTP id k8so7218056wrh.1 for ; Fri, 04 Nov 2022 06:57:40 -0700 (PDT) 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=xqYS9sbuZ09ZJd6HrHKwWvYpIRTslY8QF1bmaRD+oFs=; b=Fruok3irf43slhl5Rd5u8hygNrii3aeaSarbFXOJHubjINS8QqqoE6R+eCozQvJNeD t012FYv3TqLtSUwt8QhagtfHaviBkIL5psJ+9fIhX0by6gJLxnjnyOf8Wwd3lAy3egFz We3k+qhwNfdvzciLVoEc3TZYRng3STyIALUCluOkv4eyMFlrBSZr6FVmAM4hh7lu3CjS 3uj0sup4UensgpPGj7bEdwGh8tUclOnuhbEijpuvvohX11F7+JMVxPWwxVexuiGpl9kq hYGCRJY8i7clNGRIdlPARAGqWtMZJLST8wKHlQPFu+bVi+ZmL6Q3t9GU/BjLqE0G/EyZ ZAcg== 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=xqYS9sbuZ09ZJd6HrHKwWvYpIRTslY8QF1bmaRD+oFs=; b=A5g+zO4PeYV/uJiUNfphYA7GtYQvCKkHgw52IQk7BxsW8gkVycKWN02DEq3+cG+vgP JM1YEDy8DvxjVThHOufZo5fSh7SDITHF2mX6tyCSOmdpI932Cur5wM60TeSEqSuOwyRM NDTDRll0PoS3agiHom34s7CaKNZiqrnCNnxeQhhAt1uO+DnGEUcOQVbuL6D3EE3nT8KJ ZRGtpBU1wkz1uyzHbI3KqtvmX/VGQRzMswTxvc9uwpEHSWz2RZInAMuEN+4vZ0zYAkAs Q/0ubzHxZKu5jJ3ymErl4gjnSZwon+MTiIA4hkSK3v3eIYEo+wg9BCparFikVsD3Bok4 U5Qw== X-Gm-Message-State: ACrzQf2CabXWqSfDatxm0jkJukL/xZ4TKXWJc9qOnLrVOl5/UMXMT5Bx OLW+3bS1igwtxbtavG8eKdFRFPr5sgzCvQ== X-Google-Smtp-Source: AMsMyM7xx1ca3FEfzFnRA4E646IRDfYfz9VD87lUPxotbDeC6V5tTu77/zF66D3+7VLmpF0T84/gkw== X-Received: by 2002:a5d:4444:0:b0:236:6442:2f86 with SMTP id x4-20020a5d4444000000b0023664422f86mr239323wrr.588.1667570259560; Fri, 04 Nov 2022 06:57:39 -0700 (PDT) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id t67-20020a1c4646000000b003cf7055c057sm2981670wma.3.2022.11.04.06.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:57:39 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Subject: [COMMITTED] ada: Fix loop unnesting issue. Date: Fri, 4 Nov 2022 14:57:34 +0100 Message-Id: <20221104135734.86504-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.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 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: During loop unnesting, when the loop statements are wrapped in a code block, the newly created block's scope must be set to the loop scope (instead of the previous 'Current_Scope' that would point to an upper scope). gcc/ada/ * sem_util.ads (Add_Block_Identifier): Add new extra Scope argument. * sem_util.adb (Add_Block_Identifier): Likewise and use this scope variable instead of Current_Scope. * exp_util.adb (Wrap_Statements_In_Block): Add new scope argument to Add_Block_Identifier call. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_util.adb | 2 +- gcc/ada/sem_util.adb | 8 ++++++-- gcc/ada/sem_util.ads | 14 +++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 6c87debe456..35667028df1 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -11367,7 +11367,7 @@ package body Exp_Util is -- Create a label for the block in case the block needs to manage the -- secondary stack. A label allows for flag Uses_Sec_Stack to be set. - Add_Block_Identifier (Block_Nod, Block_Id); + Add_Block_Identifier (Block_Nod, Block_Id, Scop); -- When wrapping the statements of an iterator loop, check whether -- the loop requires secondary stack management and if so, propagate diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 28396a4c34b..9a7640b3147 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -1044,7 +1044,11 @@ package body Sem_Util is -- Add_Block_Identifier -- -------------------------- - procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is + procedure Add_Block_Identifier + (N : Node_Id; + Id : out Entity_Id; + Scope : Entity_Id := Current_Scope) + is Loc : constant Source_Ptr := Sloc (N); begin pragma Assert (Nkind (N) = N_Block_Statement); @@ -1057,7 +1061,7 @@ package body Sem_Util is -- Create a new block label and set its attributes else - Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B'); + Id := New_Internal_Entity (E_Block, Scope, Loc, 'B'); Set_Etype (Id, Standard_Void_Type); Set_Parent (Id, N); diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index c23d358e2fb..88bfbfc2086 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -88,11 +88,6 @@ package Sem_Util is -- Add A to the list of access types to process when expanding the -- freeze node of E. - procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id); - -- Given a block statement N, generate an internal E_Block label and make - -- it the identifier of the block. Id denotes the generated entity. If the - -- block already has an identifier, Id returns the entity of its label. - procedure Add_Global_Declaration (N : Node_Id); -- These procedures adds a declaration N at the library level, to be -- elaborated before any other code in the unit. It is used for example @@ -678,6 +673,15 @@ package Sem_Util is function Current_Scope return Entity_Id; -- Get entity representing current scope + procedure Add_Block_Identifier + (N : Node_Id; + Id : out Entity_Id; + Scope : Entity_Id := Current_Scope); + -- Given a block statement N, generate an internal E_Block label and make + -- it the identifier of the block. Scope denotes the scope in which the + -- generated entity Id is created and defaults to the current scope. If the + -- block already has an identifier, Id returns the entity of its label. + function Current_Scope_No_Loops return Entity_Id; -- Return the current scope ignoring internally generated loops -- 2.34.1