From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id A3252385559E for ; Thu, 6 Jul 2023 11:39:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3252385559E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-314313f127fso517053f8f.1 for ; Thu, 06 Jul 2023 04:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1688643550; x=1691235550; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AJR45OLmS1+Jk4wUHYR46/fRvH/uZ3D4g80lLyE/TMk=; b=GC+hvfAYJ+0n0ctLKXWJ8G50jTZ+IH3yN7heiyPdU8mk+ny4hc8CF+12AqwjNWY2eK BTu5rJEkLm6M0PZiulCivxMAAeboewSEmeM9RNMLAcqHvodY04M/VnE6X3sLrVSoN1i1 +1X2ENK1oEsHwzJ7w64VC9L96tVT6nZXE5vXu8O4sxYlD+cgy5dcyv2hlyKIoTQyXtED xQ1DXnngGomaJLRBYeAFZTRRTNUMMxQv6FYKDHXSzp219VgdA5VfTH6+N0j5UuoU8Rao lNeLy40UHzy3mWJcd6zqExupce5/hmNiaGaes8Dv5GDkbiT2ie+fTpUQtwprhWkIWTS+ Bkgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688643550; x=1691235550; 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=AJR45OLmS1+Jk4wUHYR46/fRvH/uZ3D4g80lLyE/TMk=; b=E42v6RR1ZkOFUGuaWH8NRQuO1622r+Krmmk0mw9DLlIcyYs2hX/kFoN0dlKdOwVqHG 6R9mMXQ1KXR43G++eaIkMplCx7/QrdYkYvDPyJ4j8pLedkYpbAHpMvpvlztS8SXlMmqk 5bMMus8G3aRJh/bOd/AoUHhbFoU02kl5c86hfT4ZTZI6r5cxZMaC1WbyScrJyOny2ygM KwVeaqC9i2NNG/VmTiJDxMInmrA4cJG9TK834VZKaSqL5ngixY3jQcWfDeLZyERSJv9O LApfFHJg0Wb+fc5Gal99hvSv2+WsRlqbjGL+qICwLtldIZSAN28rGEI8h3fRQlBW3Hjy F5OQ== X-Gm-Message-State: ABy/qLb8Ihl7aH2aZlMHbgnjlKlV1MUq90SsH6/5O3v1JPbCZxxKiZDc rTOjRm1PvMMYAhM3fmAc57I1/JiYbRVWeS/VEgCLuQ== X-Google-Smtp-Source: APBJJlEZjJHWCfzSLSS2IILmsVgd+sFeeqK+1bSzMOzjNCSqnyIAHJ6m++ov9fguh7PkHudBWlHHfg== X-Received: by 2002:adf:ee4a:0:b0:30f:af19:81f3 with SMTP id w10-20020adfee4a000000b0030faf1981f3mr1267089wro.41.1688643550343; Thu, 06 Jul 2023 04:39:10 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id p11-20020a056000018b00b003141e86e751sm1691497wrx.5.2023.07.06.04.39.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 04:39:09 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Viljar Indus Subject: [COMMITTED] ada: Evaluate static expressions in Range attributes Date: Thu, 6 Jul 2023 13:39:08 +0200 Message-Id: <20230706113908.1766256-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: From: Viljar Indus Gigi assumes that the value of range expressions is an integer literal. Force evaluation of such expressions since static non-literal expressions are not always evaluated to a literal form by gnat. gcc/ada/ * sem_attr.adb (analyze_attribute.check_array_type): Replace valid indexes with their staticly evaluated values. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_attr.adb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index 7a47abdb625..e00addd0152 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -2013,10 +2013,20 @@ package body Sem_Attr is Flag_Non_Static_Expr ("expression for dimension must be static!", E1); Error_Attr; - - elsif Expr_Value (E1) > D or else Expr_Value (E1) < 1 then - Error_Attr ("invalid dimension number for array type", E1); end if; + + declare + Value : constant Uint := Expr_Value (E1); + begin + + if Value > D or else Value < 1 then + Error_Attr ("invalid dimension number for array type", E1); + end if; + + -- Replace the static value to simplify the tree for gigi + Fold_Uint (E1, Value, True); + end; + end if; if (Style_Check and Style_Check_Array_Attribute_Index) -- 2.40.0