From patchwork Fri May 26 07:36:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 99365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp294090vqr; Fri, 26 May 2023 00:50:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6xwq7CmlHGTXn9U2o6H7JMvQrJ/X7e46x66ym/DOTsrCQs3ThGiIKFvh+OhIhiPS/8kALf X-Received: by 2002:a17:907:6e14:b0:94a:653b:ba41 with SMTP id sd20-20020a1709076e1400b0094a653bba41mr804957ejc.15.1685087436121; Fri, 26 May 2023 00:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685087436; cv=none; d=google.com; s=arc-20160816; b=Th0nFqpJe2knTskKHgttwISdouF/wwcz+fIbiZt/u+B7qxPDZHk16aSOvmBoEO4Rg7 wFzyBAqrOUgMC5OKk8xptQVNTkiDVyPNu+slNS6md4GtwrN+5gRolst8w1hs0c9gcVaq EHuSGBYAyX7waHL+HpESdjVNkNOoYSyZ/va9LNJlleNuAg7oDwNyF3qUxTiJi1xnfBi8 WQ37SYyG1+Fpa8nU8/4SwSu7ryKY80r8+ZpxBvaVX9o5LgUWO/GeJ06EZm44FM2IHOMe zg5kDTaSVUbOMwJu3cJ+gJWfazSDVeLFRwgm6+liHdntUkREBdNBd09LQF9JPKeo8S8E Udpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=mXL1x3YNuDbDEoCQWN+hf8CN444ufJj80CmHXsjU+1o=; b=pyzwQSH0P6cU7Mr8XAQKSDqrO6KCnKexuMejj7o2WTC763XPaFu1y2oxV4dvvo90D9 Gh04bok3ulRyTSUcoqZU07hLziY7ikCh96TkoyOigNkzzJyxuVTNQXGybz5Aw2nz9z3K AfkZqK5VZxMkoTVmjo43dgzJAEltuvJgD0d66e2o0SlgvD01O92eZb/ZPHoSJW34I70O jW1rDJdoTD6il5tzPlThAShqpsDJcwj8/WrCW4oL9R3uaPfg83pg/aRqtznoCrGmoElf bDcqEW5vGC3ty/oJYn7DR5WXn4dlarvciu13xSJBtph/xRFefQDBOyToAS0zQmlO3hUl O9mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="XtXrBR/q"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id fl23-20020a1709072a9700b0096f86264088si2024736ejc.624.2023.05.26.00.50.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 00:50:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="XtXrBR/q"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68E39384B828 for ; Fri, 26 May 2023 07:42:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68E39384B828 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685086955; bh=mXL1x3YNuDbDEoCQWN+hf8CN444ufJj80CmHXsjU+1o=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=XtXrBR/qSqvdP84jYldxp18Th0R4i7wkP1KCPhkjXKUV8cHAn5ozt4y4OXJhvTSVg iUhJHr6YyUFg05pQ2hFYvqUBozCrPOpHACsjmB1mY1hV9IQh5BEchjY91hnhCHgdkB EwkIM6WqQi4x39qAGFv9HV61+EDZ1okeTjEHY78g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 260FB38432F7 for ; Fri, 26 May 2023 07:36:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 260FB38432F7 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f50020e0f8so10214545e9.0 for ; Fri, 26 May 2023 00:36:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685086572; x=1687678572; 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=mXL1x3YNuDbDEoCQWN+hf8CN444ufJj80CmHXsjU+1o=; b=V4Aiz+tYCEQQsj1SWiGcyE7NfFi05o2CuiiEXS1JBJjfgWJqPyNKKMCjkC2CzEwS7F muKON+2z4/IXcXqFjet2QKkvTVSzolh3M1avdjEt4XGEvETlWhJ2ry3F21j1rJlHZeXg sMkr8dYKsZn/15ruCWA8PwzuYMIqW3syCRR9mLChNs5SHINR+7dHKqbVzYUBnDunKuP5 KyZwiL4aY4pvsYzwH0UgiDs6epsWtZvNRudLEXOi+Av3V6JajFNMcRNNmzHju7OiGN0d apzUYNGAnOUD1FaLjPlZXfwwAaHLhiRc3RzTi/IRSj0kr/LH5QA1Ct7d5OixR+AydDoY lVfA== X-Gm-Message-State: AC+VfDxz425uauyMVJimR8ZJeG9ffUcMyjObxESznxYus6ZR38U0oyg1 DBru6TvdZN+DqcgOXKuwh9S52NanH0JfWE/oVPUyFA== X-Received: by 2002:adf:fcc2:0:b0:307:7d1a:20fd with SMTP id f2-20020adffcc2000000b003077d1a20fdmr630857wrs.12.1685086571958; Fri, 26 May 2023 00:36:11 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:777b:eef4:6f79:f26f]) by smtp.gmail.com with ESMTPSA id a16-20020a5d4d50000000b003047ea78b42sm4195280wru.43.2023.05.26.00.36.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 00:36:11 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Cleanups in handling of aggregates Date: Fri, 26 May 2023 09:36:10 +0200 Message-Id: <20230526073610.2068636-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPAM_BODY, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766942243242141079?= X-GMAIL-MSGID: =?utf-8?q?1766942243242141079?= From: Piotr Trojanek Assorted cleanups related to recent fixes of aggregate handling for GNATprove; semantics is unaffected. gcc/ada/ * sem_aggr.adb (Resolve_Record_Aggregate): Remove useless assignment. * sem_aux.adb (Has_Variant_Part): Remove useless guard; this routine is only called on type entities (and now will crash in other cases). * sem_ch3.adb (Create_Constrained_Components): Only assign Assoc_List when necessary; tune whitespace. (Is_Variant_Record): Refactor repeated calls to Parent. * sem_util.adb (Gather_Components): Assert that discriminant association has just one choice in component_association; refactor repeated calls to Next. * sem_util.ads (Gather_Components): Tune whitespace in comment. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_aggr.adb | 1 - gcc/ada/sem_aux.adb | 4 ---- gcc/ada/sem_ch3.adb | 34 ++++++++++++++++++---------------- gcc/ada/sem_util.adb | 10 ++++++---- gcc/ada/sem_util.ads | 1 - 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb index e7643277460..858ae635fc2 100644 --- a/gcc/ada/sem_aggr.adb +++ b/gcc/ada/sem_aggr.adb @@ -5674,7 +5674,6 @@ package body Sem_Aggr is -- STEP 6: Find component Values - Component := Empty; Component_Elmt := First_Elmt (Components); -- First scan the remaining positional associations in the aggregate. diff --git a/gcc/ada/sem_aux.adb b/gcc/ada/sem_aux.adb index 658110f98d2..e7e096fa1cf 100644 --- a/gcc/ada/sem_aux.adb +++ b/gcc/ada/sem_aux.adb @@ -728,10 +728,6 @@ package body Sem_Aux is CList : Node_Id; begin - if not Is_Type (Typ) then - return False; - end if; - FSTyp := First_Subtype (Typ); if not Has_Discriminants (FSTyp) then diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index fb4f5badd4e..ff52e05324c 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -15161,8 +15161,8 @@ package body Sem_Ch3 is Loc : constant Source_Ptr := Sloc (Subt); Comp_List : constant Elist_Id := New_Elmt_List; Parent_Type : constant Entity_Id := Etype (Typ); - Assoc_List : constant List_Id := New_List; + Assoc_List : List_Id; Discr_Val : Elmt_Id; Errors : Boolean; New_C : Entity_Id; @@ -15191,8 +15191,10 @@ package body Sem_Ch3 is procedure Collect_Fixed_Components (Typ : Entity_Id) is begin - -- Build association list for discriminants, and find components of the - -- variant part selected by the values of the discriminants. + -- Build association list for discriminants, and find components of + -- the variant part selected by the values of the discriminants. + + Assoc_List := New_List; Old_C := First_Discriminant (Typ); Discr_Val := First_Elmt (Constraints); @@ -15293,13 +15295,13 @@ package body Sem_Ch3 is ----------------------- function Is_Variant_Record (T : Entity_Id) return Boolean is + Decl : constant Node_Id := Parent (T); begin - return Nkind (Parent (T)) = N_Full_Type_Declaration - and then Nkind (Type_Definition (Parent (T))) = N_Record_Definition - and then Present (Component_List (Type_Definition (Parent (T)))) + return Nkind (Decl) = N_Full_Type_Declaration + and then Nkind (Type_Definition (Decl)) = N_Record_Definition + and then Present (Component_List (Type_Definition (Decl))) and then - Present - (Variant_Part (Component_List (Type_Definition (Parent (T))))); + Present (Variant_Part (Component_List (Type_Definition (Decl)))); end Is_Variant_Record; -- Start of processing for Create_Constrained_Components @@ -15427,10 +15429,10 @@ package body Sem_Ch3 is Gather_Components (Typ, Component_List (Type_Definition (Parent (Typ))), - Governed_By => Assoc_List, - Into => Comp_List, - Report_Errors => Errors, - Allow_Compile_Time => True); + Governed_By => Assoc_List, + Into => Comp_List, + Report_Errors => Errors, + Allow_Compile_Time => True); pragma Assert (not Errors or else Serious_Errors_Detected > 0); Create_All_Components; @@ -15450,10 +15452,10 @@ package body Sem_Ch3 is Gather_Components (Typ, Component_List (Type_Definition (Parent (Parent_Type))), - Governed_By => Assoc_List, - Into => Comp_List, - Report_Errors => Errors, - Allow_Compile_Time => True); + Governed_By => Assoc_List, + Into => Comp_List, + Report_Errors => Errors, + Allow_Compile_Time => True); -- Note: previously there was a check at this point that no errors -- were detected. As a consequence of AI05-220 there may be an error diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 9967bd20506..d15e20b81a7 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -9788,6 +9788,8 @@ package body Sem_Util is Assoc := First (Governed_By); Find_Constraint : loop Discrim := First (Choices (Assoc)); + pragma Assert (No (Next (Discrim))); + exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim) or else @@ -9862,16 +9864,16 @@ package body Sem_Util is end if; end if; - if No (Next (Assoc)) then + Next (Assoc); + + if No (Assoc) then Error_Msg_NE - (" missing value for discriminant&", + ("missing value for discriminant&", First (Governed_By), Discrim_Name); Report_Errors := True; return; end if; - - Next (Assoc); end loop Find_Constraint; Discrim_Value := Expression (Assoc); diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index 4333c495ae7..6f5b20e5cf2 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -1080,7 +1080,6 @@ package Sem_Util is -- -- Report_Errors is set to True if the values of the discriminants are -- insufficiently static (see body for details of what that means). - -- -- Allow_Compile_Time if set to True, allows compile time known values in -- Governed_By expressions in addition to static expressions.