From patchwork Fri May 26 07:35:28 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: 70114 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 73CD03846449 for ; Fri, 26 May 2023 07:36:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 73CD03846449 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685086569; bh=uFsxlzy6vhBfdc1Y1KjnLDk5t/4IGcdNb7TS3GPGyDI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=sGqzh0ZJavzj3c8XOOb66nUhhgo1nqN++rFUIpdOEDVOWlQmkFtxozp9Am4ao3ZF2 gcCpTbVvNNoUMFp32sinMKPkG8HbweZ9ZZWCzhdLhemODoJ+F14ip71MlfX8vuVEJg /klhe8b1+FoxNJtS0bUvKFDH33+nRIrK83xQ1AOo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 80ED13858418 for ; Fri, 26 May 2023 07:35:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80ED13858418 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f6e68cc738so2780615e9.1 for ; Fri, 26 May 2023 00:35:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685086538; x=1687678538; 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=uFsxlzy6vhBfdc1Y1KjnLDk5t/4IGcdNb7TS3GPGyDI=; b=YTC8PKG4pOVHDbMJmFgA/VELs9G0g2Esx+8aPxq19mG4uLIfnKj6PACCon1Xpp3h6J c4y+hybQfQfMM0p5l/BmFCaWdG3RL5QdSeEDNNWDL4Izvs6U4lKkc+UOFAa/wUHdezxh J+yTQOa+1iDeJyKhUJUu8OrMkvtq1ikZp/KB6kWRhQPtqtIfez/H9ofEx0YnESKTFuWx 4s1zEeluLCW/Pha1ZOEwoT44+WQt6vzv03eaHO1xdaVQPnbryhWXnuFo/pZa8iJWoHYr 3VjHWomT/kTZfZjmMBAAIvxC90ACYID1gQErHNSn2zvSgLShn/nI2zznhE+U+FKziqmY tv0w== X-Gm-Message-State: AC+VfDwdkjm1JZoevHAV4iuzIcLIMFxUJI/0vKiiMjQRssT5ZG7p3uUF Su3mRIN2vpng5eE1X0pi3xhhGz0afkC6Yh3Oq2PJGA== X-Google-Smtp-Source: ACHHUZ78XSeSsiUW7piNLw+L/0TKpD5EqtQBlhIATEXVkUG1MCbj+Isp8Z9yWgX2iK8jyKatFsKDpg== X-Received: by 2002:adf:f24f:0:b0:307:904b:29e1 with SMTP id b15-20020adff24f000000b00307904b29e1mr733266wrp.20.1685086538264; Fri, 26 May 2023 00:35:38 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:777b:eef4:6f79:f26f]) by smtp.gmail.com with ESMTPSA id a18-20020adfe5d2000000b003079c402762sm4113369wrn.19.2023.05.26.00.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 00:35:37 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Enhance Is_Null_Range and Not_Null_Range predicates Date: Fri, 26 May 2023 09:35:28 +0200 Message-Id: <20230526073528.2067472-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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Eric Botcazou Both predicates bail out if the bounds of the range are not known at compile time, whereas Compile_Time_Compare can deal with them in specific cases. gcc/ada/ * sem_eval.ads (Is_Null_Range): Remove requirements of compile-time known bounds and add WARNING line. (Not_Null_Range): Remove requirements of compile-time known bounds. * sem_eval.adb (Is_Null_Range): Fall back to Compile_Time_Compare. (Not_Null_Range): Likewise. * fe.h (Is_Null_Range): New predicate. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/fe.h | 2 ++ gcc/ada/sem_eval.adb | 8 +++++--- gcc/ada/sem_eval.ads | 10 ++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h index 2d8f299903d..f283064c728 100644 --- a/gcc/ada/fe.h +++ b/gcc/ada/fe.h @@ -300,8 +300,10 @@ extern Boolean Is_Derived_Type (Entity_Id); /* sem_eval: */ #define Compile_Time_Known_Value sem_eval__compile_time_known_value +#define Is_Null_Range sem_eval__is_null_range extern Boolean Compile_Time_Known_Value (Node_Id); +extern Boolean Is_Null_Range (Node_Id, Node_Id); /* sem_util: */ diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index 905e7ff55b7..4608b1b18c1 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -5416,8 +5416,9 @@ package body Sem_Eval is return Expr_Value_R (Lo) > Expr_Value_R (Hi); end if; end; + else - return False; + return Compile_Time_Compare (Lo, Hi, Assume_Valid => False) = GT; end if; end Is_Null_Range; @@ -6028,10 +6029,11 @@ package body Sem_Eval is return Expr_Value_R (Lo) <= Expr_Value_R (Hi); end if; end; + else - return False; + return + Compile_Time_Compare (Lo, Hi, Assume_Valid => False) in Compare_LE; end if; - end Not_Null_Range; ------------- diff --git a/gcc/ada/sem_eval.ads b/gcc/ada/sem_eval.ads index c2e2b4589b8..5cb97ba057d 100644 --- a/gcc/ada/sem_eval.ads +++ b/gcc/ada/sem_eval.ads @@ -409,9 +409,9 @@ package Sem_Eval is -- an entity with Is_Known_Valid set, or Assume_No_Invalid_Values is True. function Is_Null_Range (Lo : Node_Id; Hi : Node_Id) return Boolean; - -- Returns True if it can guarantee that Lo .. Hi is a null range. If it - -- cannot (because the value of Lo or Hi is not known at compile time) then - -- it returns False. + -- Returns True if it can guarantee that Lo .. Hi is a null range + + -- WARNING: There is a matching C declaration of this subprogram in fe.h function Is_OK_Static_Expression (N : Node_Id) return Boolean; -- An OK static expression is one that is static in the RM definition sense @@ -485,9 +485,7 @@ package Sem_Eval is -- per RM 4.9(38/2). N is a node only used to post warnings. function Not_Null_Range (Lo : Node_Id; Hi : Node_Id) return Boolean; - -- Returns True if it can guarantee that Lo .. Hi is not a null range. If - -- it cannot (because the value of Lo or Hi is not known at compile time) - -- then it returns False. + -- Returns True if it can guarantee that Lo .. Hi is not a null range function Predicates_Compatible (T1, T2 : Entity_Id) return Boolean; -- In Ada 2012, subtypes are statically compatible if the predicates are