From patchwork Tue May 17 08:27:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 54068 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 29FB33857407 for ; Tue, 17 May 2022 08:34:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29FB33857407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652776471; bh=eLNie01H0dSSp0/ufzdkOjEF2ebEm2Chide7Cdf6wiU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Gqp7v17EwYEX6YOEKuT2Ig3/10D+t7aJzSbhUJid0LsQVImRdhLdtAFwqnrEjtXLL Sr6A7e0We6RZ6oOCAcv9HYGZRS8ISbwnOnMHcO6UrgNEa3pVmv+i4BJVRlV9fVA0CC Ag/PTg7C0rHu1O13s6Zgin81CpqSNrL75umuh7Bg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id E10F6385781D for ; Tue, 17 May 2022 08:27:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E10F6385781D Received: by mail-wr1-x42b.google.com with SMTP id f2so16640765wrc.0 for ; Tue, 17 May 2022 01:27:34 -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=eLNie01H0dSSp0/ufzdkOjEF2ebEm2Chide7Cdf6wiU=; b=8J3AbYsjUBkKz9ORryOb9HRHGnlBwlb+VMV8sFYBbcT+FzJZkckM/sRAzYzYHb/Pe5 ojZJVOnsok5pU6W8c+EjGV6F4VUlq4XnQq042PvXpOGNKVm8Aqh7eqXOBCMWDFtlgk52 LOuReJVvP+kfufyRIwO/slhnsVv+2k3g9AKlvrHyin0k6tjfLakF5nN6kK1cy6SFdwhU nor2ipqCzLeYx4AChqerfwmVndLW3NTo70WxK7uiGsDK06tVXKasbH2O3hssGduC/ggn sm4FQsTeHx0msW1KwlAf9O5dyceZfQnOT4KCkqMxRUMoD/ffNgML420HoI6c4JyGLCBJ aKOQ== X-Gm-Message-State: AOAM530gLjp3PewKApgn1vHUdJmSc9f1kJz5L2Qur5zdHidNSVpCSuO7 yBefSVxLYxjXuijq3DIct838La3wTlNotyLZ X-Google-Smtp-Source: ABdhPJzGzNJdy+DSrIkb9vYf0LkbeVidu7RiG/WUuQE1gXR0mDEBFmu/ySXT5lTH8e6THG+o9EKYcA== X-Received: by 2002:a05:6000:1866:b0:20d:2834:5155 with SMTP id d6-20020a056000186600b0020d28345155mr3052810wri.101.1652776053746; Tue, 17 May 2022 01:27:33 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id az25-20020a05600c601900b003942a244ec0sm1624723wmb.5.2022.05.17.01.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:27:33 -0700 (PDT) Date: Tue, 17 May 2022 08:27:32 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Crash freezing declaration that will raise constraint error Message-ID: <20220517082732.GA1088149@adacore.com> MIME-Version: 1.0 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-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Javier Miranda Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When the compiler is built with assertions enabled and processes the following declarations: type Vector_Boolean_Array is array (1 .. 10) of Boolean; O2 : constant Vector_Boolean_Array := [for J in 2 => True]; The expression is rewritten by the frontend with an N_Raise_CE node, which leads to an assertion error at the freezing point of the object declaration. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * freeze.adb (Freeze_Entity): Protect the call to Declaration_Node against entities of expressions replaced by the frontend with an N_Raise_CE node. diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -6582,9 +6582,13 @@ package body Freeze is end if; end if; - -- Special processing for objects created by object declaration + -- Special processing for objects created by object declaration; + -- we protect the call to Declaration_Node against entities of + -- expressions replaced by the frontend with an N_Raise_CE node. - if Nkind (Declaration_Node (E)) = N_Object_Declaration then + if Ekind (E) in E_Constant | E_Variable + and then Nkind (Declaration_Node (E)) = N_Object_Declaration + then Freeze_Object_Declaration (E); end if;