From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 2373A385C327 for ; Mon, 4 Jul 2022 07:50:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2373A385C327 Received: by mail-ed1-x535.google.com with SMTP id x10so3258700edd.13 for ; Mon, 04 Jul 2022 00:50:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=Vvimp+isEr9ylvmrV6vGf5FOzQmO88hFhI3VB9l9s8g=; b=kp2amr/EpJnOxnQ/W7TJtc1uAbHFhXTqzcFMaxAPNS4P0oFYND67ayLWmKko6ZRjGG gijvpvsLtD6o+aYjZEQOtxyzsATSx+Xlf8HyZ7EW6g0WNTHsm/Pa4Ziu9681jusPzr+u wVFUwTj4ISnGFH1reIyRGJKP1UPmG0YVYhcUHOfWDjxINS/72ShAhOn/OLbqSsEhwVRw n+aGD7Z3L83FG3iaASO/5zX/XeOBTWK+LTJ9i1GV95hCF32VeCWhLuNHAMvCsSy1rf6L 0ulzn8LbBdYm5q0GPpSbL10RtGlwG66U1nfDh6H6V56+eDFPIMP5EM9SUBwOXVaZFwWt Qsqg== X-Gm-Message-State: AJIora++ecO5RRCVuvdXruXKWobbyfACG4lcqZrbpLq0hDnl29jfkpiN FdIFq5iaIG9LizrpXeP7OCAF64AUM6qN8w== X-Google-Smtp-Source: AGRyM1sQjZYge/5TeIvIOVl4K4tqqdaJVpCmRYveCv/HtPy986MvbJWd+ASY3Lsudade8Rqt6Vb9Aw== X-Received: by 2002:a05:6402:15a:b0:431:71b9:86f3 with SMTP id s26-20020a056402015a00b0043171b986f3mr36117326edu.249.1656921018737; Mon, 04 Jul 2022 00:50:18 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id m14-20020a1709061ece00b007121361d54asm13784803ejj.25.2022.07.04.00.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 00:50:18 -0700 (PDT) Date: Mon, 4 Jul 2022 07:50:17 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Fix missing error on 'Access of constrained array Message-ID: <20220704075017.GA99194@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Qxx1br4bt0+wmkIi" Content-Disposition: inline X-Spam-Status: No, score=-13.2 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 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-List-Received-Date: Mon, 04 Jul 2022 07:50:21 -0000 --Qxx1br4bt0+wmkIi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline For X'Access, the designated subtype of the access type must statically match the nominal subtype of X. This patch fixes a bug where the error was not detected when there is an unrelated declaration of the form "Y : T := X;", where T is an unconstrained array subtype. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_util.adb (Expand_Subtype_From_Expr): Generate a new subtype when Is_Constr_Subt_For_UN_Aliased is True, so the Is_Constr_Subt_For_U_Nominal flag will not be set on the preexisting subtype. * sem_attr.adb, sem_ch3.adb: Minor. --Qxx1br4bt0+wmkIi Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -113,7 +113,7 @@ package body Exp_Util is (Header_Num => Type_Map_Header, Key => Entity_Id, Element => Node_Or_Entity_Id, - No_element => Empty, + No_Element => Empty, Hash => Type_Map_Hash, Equal => "="); @@ -5730,8 +5730,17 @@ package body Exp_Util is or else not Is_Array_Type (Exp_Typ) or else not Aliased_Present (N)) then - if Is_Itype (Exp_Typ) then + if Is_Itype (Exp_Typ) + -- If Exp_Typ was created for a previous declaration whose nominal + -- subtype is unconstrained, and that declaration is aliased, + -- we need to generate a new subtype, because otherwise the + -- Is_Constr_Subt_For_U_Nominal flag will be set on the wrong + -- subtype, causing failure to detect non-statically-matching + -- subtypes on 'Access of the previously-declared object. + + and then not Is_Constr_Subt_For_UN_Aliased (Exp_Typ) + then -- Within an initialization procedure, a selected component -- denotes a component of the enclosing record, and it appears as -- an actual in a call to its own initialization procedure. If @@ -5770,7 +5779,7 @@ package body Exp_Util is -- This type is marked as an itype even though it has an explicit -- declaration since otherwise Is_Generic_Actual_Type can get -- set, resulting in the generation of spurious errors. (See - -- sem_ch8.Analyze_Package_Renaming and sem_type.covers) + -- sem_ch8.Analyze_Package_Renaming and Sem_Type.Covers.) Set_Is_Itype (T); Set_Associated_Node_For_Itype (T, Exp); diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -11632,9 +11632,7 @@ package body Sem_Attr is end if; end if; - if (Attr_Id = Attribute_Access - or else - Attr_Id = Attribute_Unchecked_Access) + if Attr_Id in Attribute_Access | Attribute_Unchecked_Access and then (Ekind (Btyp) = E_General_Access_Type or else Ekind (Btyp) = E_Anonymous_Access_Type) then diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -18276,7 +18276,7 @@ package body Sem_Ch3 is begin -- If the parent is a component_definition node we climb to the - -- component_declaration node + -- component_declaration node. if Nkind (P) = N_Component_Definition then P := Parent (P); --Qxx1br4bt0+wmkIi--