From patchwork Tue May 30 07:20:59 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: 100593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1996790vqr; Tue, 30 May 2023 00:27:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4UplwL+sq/LKnJbjEz7Up4ZPj3bGs5HSXG1eon0KauQGdrrsf7mVQY1aHOT7qqpDSUZBjO X-Received: by 2002:a17:907:7e8c:b0:971:1717:207b with SMTP id qb12-20020a1709077e8c00b009711717207bmr1564226ejc.35.1685431635401; Tue, 30 May 2023 00:27:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685431635; cv=none; d=google.com; s=arc-20160816; b=N80UioOm2ALfksneL8d7xA/+h7AH7w0CVDrmUmME1MbRjdMUqULTEgstedmPzJyKUp YvFqdXcCdZUQRfRFe8h/mNgi1Qi2zUjmOkb1rH827zXzZYHSMo3VmXM1gZMJ4lVHeQEN 7pnmLzSSeykpUJc2iZrIkYt76C7Ud955z0Je1S8K+sEXnoayB3wm37N05C7obecrvFy7 UPrhwGHZZYcN/dUTC4pwmCILH5sDjQO+b/mZab8+u5eDx15VrzkmWzLea8+D6BTm3ooV Tg+SMJj5rH3+sgIwE4uWxsrafptxBn/Q1Yt5784dSCXW5+vFZZuw7tGOYB5mdPZHYn5g vjOg== 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=CYzQ39RzbBXwCCq6biADmUVsQNn/bt6PRN8DU0pSDSM=; b=NbIbIz4o2VhJoX4pclLwxFkPz+HEoZ27nkdwRCU9jxVjOjSCk78T8DoYYLKJu58q5a 4TUxKvBLHRwNBS9OAVllPGRQhRFwAsdq1EVZDdsPIFk5xDwgYyKRiDeKuhS7kBv+JZxR ozYE40yfzYjzX1PEWZvoIvSk+7JppkWerHJGmRu5ibR7E8luUUz/+zPclXwEk6JhYgRV 3q2cIDFRBRbaWmIj/3K+iD8h+L1fzppZbkvnbROiEprt4b1CbcB727AE7AZUwOFrfNyX VxTQr8I5dK8QRVqENffONM+PxpeJCr+fcfhYcHI6/3FnlbB6BZ4oRy+xsP5GgB+C3bjd ilIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=E6NxkcbP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ev3-20020a17090729c300b00969cb636104si371494ejc.949.2023.05.30.00.27.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:27:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=E6NxkcbP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 2943A386BB6B for ; Tue, 30 May 2023 07:23:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2943A386BB6B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431424; bh=CYzQ39RzbBXwCCq6biADmUVsQNn/bt6PRN8DU0pSDSM=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=E6NxkcbPxHGhFUz92lgBT9PyUgjxwhl5n0pxyB9D2DNNmy/iHNjpgyHVh9X/DlJf2 VV1QSIFszE0KoGHNfACTs6ysZ3KWbhmrhJKIcRMalr4xgZqa7m4iw1GLsYHseRHmVI Z6Q0GfeaGrJ1F295/J5noTaV17GBEEoX052czTBg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 1565A38558B0 for ; Tue, 30 May 2023 07:21:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1565A38558B0 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-30ad8f33f1aso2477517f8f.0 for ; Tue, 30 May 2023 00:21:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685431261; x=1688023261; 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=CYzQ39RzbBXwCCq6biADmUVsQNn/bt6PRN8DU0pSDSM=; b=TVaebVawRAEFEBId8MEiWczUOsYBMDc8fzBSYUvl/KDW8dCKuvcLn6F77zHprfAKDT KxQXGOLoNrie/kQ5yrwjiXzc5GSo5D8IDSKzm5OTNXpGZN00gZfb2WHwgQxoxiMMqHRM EidpLlSLaHRUGEkNETQTxJQxuymHWxbatcoPNRin/3yTo1pRCw6GK5hX8lN6vumvEF3L gPU5ncvGooqcuQzekkaQ749eZXY8pNhw8zgzi73QevlMQ1u7VgerX5z2BoZTAD2KyE/F PhtwV2P4NYOOn5WmADB+VvsIgSjV7wigp8fZpIBjI9o8kd1vrGdUTZLgoWKVkuOeP+6M tvKA== X-Gm-Message-State: AC+VfDx+USFol6E6wb+9SSjn4LUvaLn5WtmB4wbwG//LnO+8PAdZ1rcg 0Jnmwx6zpy9QOqOEyxtKif5JLS8ayqkY8G2IIGtirQ== X-Received: by 2002:adf:e8c5:0:b0:30a:f2a5:83dd with SMTP id k5-20020adfe8c5000000b0030af2a583ddmr814978wrn.7.1685431260915; Tue, 30 May 2023 00:21:00 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:7733:a608:a415:6b2a]) by smtp.gmail.com with ESMTPSA id b9-20020adfe309000000b003079986fd71sm2257958wrj.88.2023.05.30.00.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:21:00 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix internal error on array constant in expression function Date: Tue, 30 May 2023 09:20:59 +0200 Message-Id: <20230530072059.2500113-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 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: =?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?1767303162365018934?= X-GMAIL-MSGID: =?utf-8?q?1767303162365018934?= From: Eric Botcazou This happens when the peculiar check emitted by Check_Large_Modular_Array is applied to an object whose actual subtype is an itype with dynamic size, because the first reference to the itype in the expanded code may turn out to be within the raise statement, which is problematic for the eloboration of this itype by the code generator at library level. gcc/ada/ * freeze.adb (Check_Large_Modular_Array): Fix head comment, use Standard_Long_Long_Integer_Size directly and generate a reference just before the raise statement if the Etype of the object is an itype declared in an open scope. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/freeze.adb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index 8ebf10bd576..83ce0300871 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -4110,9 +4110,10 @@ package body Freeze is procedure Check_Large_Modular_Array (Typ : Entity_Id); -- Check that the size of array type Typ can be computed without -- overflow, and generates a Storage_Error otherwise. This is only - -- relevant for array types whose index has System_Max_Integer_Size - -- bits, where wrap-around arithmetic might yield a meaningless value - -- for the length of the array, or its corresponding attribute. + -- relevant for array types whose index is a modular type with + -- Standard_Long_Long_Integer_Size bits: wrap-around arithmetic + -- might yield a meaningless value for the length of the array, + -- or its corresponding attribute. procedure Check_Pragma_Thread_Local_Storage (Var_Id : Entity_Id); -- Ensure that the initialization state of variable Var_Id subject @@ -4170,8 +4171,24 @@ package body Freeze is -- Storage_Error. if Is_Modular_Integer_Type (Idx_Typ) - and then RM_Size (Idx_Typ) = RM_Size (Standard_Long_Long_Integer) + and then RM_Size (Idx_Typ) = Standard_Long_Long_Integer_Size then + -- Ensure that the type of the object is elaborated before + -- the check itself is emitted to avoid elaboration issues + -- in the code generator at the library level. + + if Is_Itype (Etype (E)) + and then In_Open_Scopes (Scope (Etype (E))) + then + declare + Ref_Node : constant Node_Id := + Make_Itype_Reference (Obj_Loc); + begin + Set_Itype (Ref_Node, Etype (E)); + Insert_Action (Declaration_Node (E), Ref_Node); + end; + end if; + Insert_Action (Declaration_Node (E), Make_Raise_Storage_Error (Obj_Loc, Condition =>