From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id D245C385AC22 for ; Fri, 4 Nov 2022 13:58:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D245C385AC22 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-x32f.google.com with SMTP id i5-20020a1c3b05000000b003cf47dcd316so5462217wma.4 for ; Fri, 04 Nov 2022 06:58:06 -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=w7U/l8RjTIFuFGlr6+NFa/o+lff/UZ0x5zYXsLqDJHM=; b=blRyVAOUmzf7rHSBKAjSy0AO2CZshFoJzn+Eh7d7Qy1M7j6dLY9Bh2Xj+SsD9mBMHX /NAoEHQIxivQanpjFLHplbCI4VD8q4Wz0RAjEuOkL1HEzpupAv73/bOSXfujUmQySuZ5 eCesuApqw2EsNyilOvgjMqIZrU3PBks3Nbh7MR6WADWUMafRx/ah3wOBwuluBJ5erWBi 3yZNE8f7TFnAxqCppaEfqm/uKwK4xwe/usfPOJpk0u/A6tVVoVIi1HPOoiEsDuqUdTsp II1RrG0StirR8NpWIeBpkQBkXtP9y3LpqQqcUgdXKH8CjBwI/i2NT+BiNRN/4cFsySZn BFeQ== 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=w7U/l8RjTIFuFGlr6+NFa/o+lff/UZ0x5zYXsLqDJHM=; b=OwTtx2qrYqdZuibfrc0HXXeCfPiPmNZKY99gUZe/3/REj/NI/RmWZbluU1m4PqLGON Ugu3uH80qbxKJfUNJ6A6gszkvJmnml4Ml0hmlIWjwwZ1skUEWvKPPYCOozfxkSzOWpqz i3T736r+wVJSvgjQADW5vjzqAnoPuUvyfGEdAadcQmWXIjJ4+5mQxa4bOBnvJnMVgluK AwmZfXdRYxUowqdUEz9erWOn2VbDG7Dpe8aiII3gMuq3jYQsKLMKlWzBO20L+RvHM4qB lTRXi2N+VGoxRcK0CUpBeWf06vWbS37xMVCfLvUT4TkMKioaKck1porZBLVMW0LFETxV gJyA== X-Gm-Message-State: ACrzQf284gEbv8WBGB+tNElkQ0gPITz2kWuKTYgE7rNZAmnMntBaVAu7 Qq1MydVYESb4qo2W8/5vdySB0sPFKkK+/w== X-Google-Smtp-Source: AMsMyM4nEyNau71MsnfBUQe1OaKZi3KwBRyYctiyLEz23zzLWTvbIOwbcusdUxz3mAchN4rLDPFatg== X-Received: by 2002:a1c:7c14:0:b0:3b5:1133:d2ed with SMTP id x20-20020a1c7c14000000b003b51133d2edmr23712085wmc.133.1667570285681; Fri, 04 Nov 2022 06:58:05 -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 e7-20020a5d5007000000b00236644228besm3546227wrt.40.2022.11.04.06.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:58:05 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Avoid repeated iteration over private protected components Date: Fri, 4 Nov 2022 14:58:01 +0100 Message-Id: <20221104135801.86694-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: From: Piotr Trojanek The First_Entity/Next_Entity chain includes private entities, so there it no need to iterate starting both from First_Entity and First_Private_Entity. Code cleanup related to improved detection of references to uninitialized objects; behavior is unaffected. gcc/ada/ * sem_util.adb (Check_Components): Iterate using First/Next_Component_Or_Discriminant. (Has_Preelaborable_Initialization): Avoid repeated iteration with calls to Check_Components with First_Entity and First_Private_Entity. (Is_Independent_Object_Entity): Tune indentation. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_util.adb | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 9a7640b3147..536d5fadefb 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -13679,15 +13679,12 @@ package body Sem_Util is Exp : Node_Id; begin - -- Loop through entities of record or protected type + -- Loop through components and discriminants of record or protected + -- type. - Ent := E; + Ent := First_Component_Or_Discriminant (E); while Present (Ent) loop - -- We are interested only in components and discriminants - - Exp := Empty; - case Ekind (Ent) is when E_Component => @@ -13698,6 +13695,8 @@ package body Sem_Util is if Present (Declaration_Node (Ent)) then Exp := Expression (Declaration_Node (Ent)); + else + Exp := Empty; end if; when E_Discriminant => @@ -13710,7 +13709,7 @@ package body Sem_Util is Exp := Discriminant_Default_Value (Ent); when others => - goto Check_Next_Entity; + raise Program_Error; end case; -- A component has PI if it has no default expression and the @@ -13731,8 +13730,7 @@ package body Sem_Util is exit; end if; - <> - Next_Entity (Ent); + Next_Component_Or_Discriminant (Ent); end loop; end Check_Components; @@ -13842,7 +13840,7 @@ package body Sem_Util is -- If OK, check extension components (if any) if Has_PE and then Is_Record_Type (E) then - Check_Components (First_Entity (E)); + Check_Components (E); end if; -- Check specifically for 10.2.1(11.4/2) exception: a controlled type @@ -13882,7 +13880,7 @@ package body Sem_Util is elsif Is_Record_Type (E) then Has_PE := True; - Check_Components (First_Entity (E)); + Check_Components (E); -- Protected types must not have entries, and components must meet -- same set of rules as for record components. @@ -13892,8 +13890,7 @@ package body Sem_Util is Has_PE := False; else Has_PE := True; - Check_Components (First_Entity (E)); - Check_Components (First_Private_Entity (E)); + Check_Components (E); end if; -- Type System.Address always has preelaborable initialization @@ -18305,7 +18302,7 @@ package body Sem_Util is Is_Object (Id) and then (Is_Independent (Id) or else - Is_Independent (Etype (Id))); + Is_Independent (Etype (Id))); end Is_Independent_Object_Entity; ------------------------------------- -- 2.34.1