From patchwork Tue May 30 07:21:20 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: 1787307 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=F++ZuicU; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QVkWy6syxz20Py for ; Tue, 30 May 2023 17:28:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F39223830B5B for ; Tue, 30 May 2023 07:28:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F39223830B5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431693; bh=sRIJq2jSxmcZFAsngiW7vxb81KBVu3yHcneBCyBCrSM=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=F++ZuicUjuTz2+KCaXG/DuimOdJs6Bcb3MqaoKF2YY+xIXc05uP2pDboCo5X9Gwwn g+d2J9yqeQQH1TpI/y3RFgHexRfV/uxAf+n61GEL1FW3One3bclBvN2/U/sCT+JUT8 koo1IBC7InOC0vfPTTL9SjzMfny08B7uSKHka+eU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id E714B3856634 for ; Tue, 30 May 2023 07:21:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E714B3856634 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-30aa1eb95a0so4096745f8f.1 for ; Tue, 30 May 2023 00:21:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685431282; x=1688023282; 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=sRIJq2jSxmcZFAsngiW7vxb81KBVu3yHcneBCyBCrSM=; b=RaOGa2fa5IuH8qxP5oSKpg4ZOcyzprOCMZqN1+Pg6UoQQxWM/YYte/SjYt4+MKzfph kTbNdbQRTzoL8RMXlRQMLAcaWzFmdhcAkZYpbFc3aMnco9EQTMlre8zy8gWl2gIXK6BH yC+PSUZVb1eACxccNl8mZFOzLZCkzswdLgrC/gxA5Qmhigf0uFLl2leLkbnDaM2naaGB 5XaAoyVyYjcmMEmP2qYYiokSyxNVnLfbgbRA7GPnN/+kWKVONQT6KiE5jcVH97X+dzTH 28gR7g4fhiON5a74d8gYcAxpYrPxI23JScGj1L9BmAyWtQsTrawtVPdBanKzF7BbSBbv QocQ== X-Gm-Message-State: AC+VfDx58ZdPmqyeJf7yX0vO8dzTnyFWFUZBTgsIWSc0kLSkF/Fj5r5J XyaOil06gT9+h2Jw58/PARfgwpZayT/jbybgFaYNgw== X-Google-Smtp-Source: ACHHUZ6kcxCX/T+p/Am5WZSTiD24nbArkzVkPRpFKEYrLsqMQCMBSqg2naXoefAe7+pllZvemIHWbg== X-Received: by 2002:a5d:51d2:0:b0:30a:df14:516b with SMTP id n18-20020a5d51d2000000b0030adf14516bmr710090wrv.6.1685431282584; Tue, 30 May 2023 00:21:22 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:7733:a608:a415:6b2a]) by smtp.gmail.com with ESMTPSA id k11-20020adfe3cb000000b003078a3f3a24sm2208240wrm.114.2023.05.30.00.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:21:22 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix bogus Storage_Error on dynamic array with static zero length Date: Tue, 30 May 2023 09:21:20 +0200 Message-Id: <20230530072120.2500814-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.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: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" From: Eric Botcazou This works around the limitations present for the support of arrays in the middle-end by clearing the TREE_OVERFLOW flag for arrays with zero length. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) : Use a local variable for the GNAT index type. : Likewise. Call Is_Null_Range on the bounds and force the zero on TYPE_SIZE and TYPE_SIZE_UNIT if it returns true. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/decl.cc | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc index 456fe53737d..e5e04ddad93 100644 --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -2241,9 +2241,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) index += (convention_fortran_p ? - 1 : 1), gnat_index = Next_Index (gnat_index)) { + const Entity_Id gnat_index_type = Etype (gnat_index); const bool is_flb - = Is_Fixed_Lower_Bound_Index_Subtype (Etype (gnat_index)); - tree gnu_index_type = get_unpadded_type (Etype (gnat_index)); + = Is_Fixed_Lower_Bound_Index_Subtype (gnat_index_type); + tree gnu_index_type = get_unpadded_type (gnat_index_type); tree gnu_orig_min = TYPE_MIN_VALUE (gnu_index_type); tree gnu_orig_max = TYPE_MAX_VALUE (gnu_index_type); tree gnu_index_base_type = get_base_type (gnu_index_type); @@ -2479,6 +2480,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) const int ndim = Number_Dimensions (gnat_entity); tree gnu_base_type = gnu_type; tree *gnu_index_types = XALLOCAVEC (tree, ndim); + bool *gnu_null_ranges = XALLOCAVEC (bool, ndim); tree gnu_max_size = size_one_node; bool need_index_type_struct = false; int index; @@ -2494,7 +2496,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) gnat_index = Next_Index (gnat_index), gnat_base_index = Next_Index (gnat_base_index)) { - tree gnu_index_type = get_unpadded_type (Etype (gnat_index)); + const Entity_Id gnat_index_type = Etype (gnat_index); + tree gnu_index_type = get_unpadded_type (gnat_index_type); tree gnu_orig_min = TYPE_MIN_VALUE (gnu_index_type); tree gnu_orig_max = TYPE_MAX_VALUE (gnu_index_type); tree gnu_index_base_type = get_base_type (gnu_index_type); @@ -2671,6 +2674,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) = create_index_type (gnu_min, gnu_high, gnu_index_type, gnat_entity); + /* Record whether the range is known to be null at compile time + to disambiguate it from too large ranges. */ + const Entity_Id gnat_ui_type = Underlying_Type (gnat_index_type); + gnu_null_ranges[index] + = Is_Null_Range (Type_Low_Bound (gnat_ui_type), + Type_High_Bound (gnat_ui_type)); + /* We need special types for debugging information to point to the index types if they have variable bounds, are not integer types, are biased or are wider than sizetype. These are GNAT @@ -2737,7 +2747,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) if (array_type_has_nonaliased_component (gnu_type, gnat_entity)) set_nonaliased_component_on_array_type (gnu_type); - /* Kludge to remove the TREE_OVERFLOW flag for the sake of LTO + /* Clear the TREE_OVERFLOW flag, if any, for null arrays. */ + if (gnu_null_ranges[index]) + { + TYPE_SIZE (gnu_type) = bitsize_zero_node; + TYPE_SIZE_UNIT (gnu_type) = size_zero_node; + } + + /* Kludge to clear the TREE_OVERFLOW flag for the sake of LTO on maximally-sized array types designed by access types. */ if (integer_zerop (TYPE_SIZE (gnu_type)) && TREE_OVERFLOW (TYPE_SIZE (gnu_type))