From patchwork Fri Sep 2 07:53:28 2022 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: 57271 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA79A383CCFC for ; Fri, 2 Sep 2022 07:56:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA79A383CCFC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662105415; bh=+AYSqlIB+GGOF0cJFe93N4FzhlJm2XjkYEOV9JTqeKE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=wWT9LXCeLKYe8xEC3SyPfHJRHgEbPxas7Kx7B6+1QRFXFH7htMDijoT68ip5klhBi GboKMfV1OWUDYWJgCA5TxgvmgSLXURevnl4oq4XHi6OHMDdQE8VIpAMGNueRUloD1j +apccWHQhLgTiyQjlw5NrJaTh+DwqThphNjF2Am4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id EA6333858015 for ; Fri, 2 Sep 2022 07:53:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EA6333858015 Received: by mail-wm1-x332.google.com with SMTP id j26so793358wms.0 for ; Fri, 02 Sep 2022 00:53:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=+AYSqlIB+GGOF0cJFe93N4FzhlJm2XjkYEOV9JTqeKE=; b=zRXaDCpEFv7ZU/QsOBlh8O+Vec82NCCEyu2i9CIq1O0n2XfS9KA5q9Wxm3JV1fvEW7 7mfwyNTM4bt2N/8JpBzG+1WrRNb4a406UaU7wpkf1QpzWzfaTaEi+LUp1LqlVu9jJg/x /zTWFcU8SQwJaYheJR8kdlHKR7vhmVySnRfGksqzy8Er43R0mqQgyNTiBEHVeOLAZ2QO awVBP/6w5BP8bufkoISJz4WpB0NHjNeuhldfb70l4OiYyBXw0YZ1A/u1dAuVP8xDEHPu eZ5rr3yo+S7jjYtg5nP38YnRIS24NKtekUqNUAtUSV5ifLS8NBti6jCVuJ8Kx0/VDfPn tWlQ== X-Gm-Message-State: ACgBeo2autMoB599EwynHdTGDwUdP0PE1mZbOJq3TSGiE2TI7u/pxKpN jKisXK3qsUmA989l1DzUjyiL57lDDXSFbA== X-Google-Smtp-Source: AA6agR4+Xyn0x9UeSlLwD3azePL0FGM2rT3qyeMqSB0YDg+JEhOvAmgc6/pCr7zAgehSTuerAJXD+A== X-Received: by 2002:a05:600c:2c47:b0:3a6:4623:4ccf with SMTP id r7-20020a05600c2c4700b003a646234ccfmr1949202wmg.85.1662105209813; Fri, 02 Sep 2022 00:53:29 -0700 (PDT) Received: from poulhies-Precision-5550 (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id p7-20020a05600c358700b003a3561d4f3fsm1468500wmq.43.2022.09.02.00.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 00:53:29 -0700 (PDT) Date: Fri, 2 Sep 2022 09:53:28 +0200 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix crash on declaration of overaligned array with constraints Message-ID: <20220902075328.GA1121076@poulhies-Precision-5550> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.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 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: Marc =?iso-8859-1?q?Poulhi=E8s?= Cc: Eric Botcazou Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The semantic analyzer was setting the Is_Constr_Subt_For_UN_Aliased flag on the actual subtype of the object, which is incorrect because the nominal subtype is constrained. This also adjusts a recent related change. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_util.adb (Expand_Subtype_From_Expr): Check for the presence of the Is_Constr_Subt_For_U_Nominal flag instead of the absence of the Is_Constr_Subt_For_UN_Aliased flag on the subtype of the expression of an object declaration before reusing this subtype. * sem_ch3.adb (Analyze_Object_Declaration): Do not incorrectly set the Is_Constr_Subt_For_UN_Aliased flag on the actual subtype of an array with definite nominal subtype. Remove useless test. 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 @@ -5732,14 +5732,17 @@ package body Exp_Util is 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) + -- When this is for an object declaration, the caller may want to + -- set Is_Constr_Subt_For_U_Nominal on the subtype, so we must make + -- sure that either the subtype has been built for the expression, + -- typically for an aggregate, or the flag is already set on it; + -- otherwise it could end up being set on the nominal constrained + -- subtype of an object and thus later cause the failure to detect + -- non-statically-matching subtypes on 'Access of this object. + + and then (Nkind (N) /= N_Object_Declaration + or else Nkind (Exp) = N_Aggregate + or else Is_Constr_Subt_For_U_Nominal (Exp_Typ)) then -- Within an initialization procedure, a selected component -- denotes a component of the enclosing record, and it appears as 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 @@ -4770,20 +4770,13 @@ package body Sem_Ch3 is if not Is_Entity_Name (Object_Definition (N)) then Act_T := Etype (E); Check_Compile_Time_Size (Act_T); - - if Aliased_Present (N) then - Set_Is_Constr_Subt_For_UN_Aliased (Act_T); - end if; end if; -- When the given object definition and the aggregate are specified -- independently, and their lengths might differ do a length check. -- This cannot happen if the aggregate is of the form (others =>...) - if not Is_Constrained (T) then - null; - - elsif Nkind (E) = N_Raise_Constraint_Error then + if Nkind (E) = N_Raise_Constraint_Error then -- Aggregate is statically illegal. Place back in declaration