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: 922 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp611805wro; Fri, 2 Sep 2022 00:59:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR4+6ENGGE/EAPL0n1qmO819TQytOotQeGlQmvtWuEhpdmF0SztvVA/6an1bSG+b6z+i9SPA X-Received: by 2002:a05:6402:11cd:b0:43d:7862:7c25 with SMTP id j13-20020a05640211cd00b0043d78627c25mr32712397edw.96.1662105543206; Fri, 02 Sep 2022 00:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662105543; cv=none; d=google.com; s=arc-20160816; b=gQOQXQ9TypB3FdpXcw3NJm/uUmP8xoXM0TGk0baMyuk2yM+4R9TSNd6rrJFst9Xpvc c8TQWKA3gIPgWHRqMAABMD8YGgqWkg7u+TdRG35fENJf8knK6di8Dn6aCc8SFm+Fuhkd uClHdPC+zHRFGSAPOM8+UvPDRIAxflvS4r94FzNRerzdN0hIwq8QoU+KfBgGkC89GunK pwlakRXXG8ENB5ewWQovrcTKxbSRArQFcyxghYTAXr9DHaPb73YI0mEY1+NvMw7rtPka kscNVzs0si1fwYS67FA0Z+NK6Oct9mUBNOw4aIlprR5nEqkkWdrb0GAzML35mMUw85Ix LLmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+AYSqlIB+GGOF0cJFe93N4FzhlJm2XjkYEOV9JTqeKE=; b=Rha5WNVLOAnK+/583489mxMipfnf31fgYrcFVBv3vOBiDsRqhEH0gmT99XwxAwOn76 VB1VWGsWg9S36Kk3UbVBV/0QvAf+Rih4LwVXRr0qp8I2O6LTBgUTR42yF+VW5ocsYnes W7MDuHdsOAo/tImgLw0qN/Rx8imEfmhE3EAR52J7EAZWhmIcI43q4PSJQ3EAu/9gJwZa k+TlqVNAqrheXKrFurk3TvtdRJnkeXu+utAbgkvJ8FITm2b8HAjoAvu3/WSvpZkjzN6z eNAEKeFP0u3GjiSfhNqW05STLhwSOUGivFNm3vppE0hZJLw3AU/GX2WVM/nL2P00tgDV Olcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dALl3b8U; 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 y17-20020a170906471100b0073ddd228877si1156246ejq.156.2022.09.02.00.59.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 00:59:03 -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=dALl3b8U; 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 234DD3884F0A for ; Fri, 2 Sep 2022 07:57:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 234DD3884F0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662105430; 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=dALl3b8UTmlZnNGbFNd5zuP/7V9NpBQvfHwefUeD7VlbYDKa8PERkH2o9kVIA0y82 L97c3l8g6dkEJ6T1yV4aNtP/pcnw/CCzf7CnGxMZzJvin55neCKRaPoMFyrwTRDAzx en7LsQhCq/qIMPSZzQgoQW+9BRb53OXJYTwzbTHI= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742843982201970056?= X-GMAIL-MSGID: =?utf-8?q?1742843982201970056?= 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