From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id E7A583857342 for ; Mon, 5 Sep 2022 07:25:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E7A583857342 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-x430.google.com with SMTP id e13so10100406wrm.1 for ; Mon, 05 Sep 2022 00:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date; bh=oLydZfU59BQFgQ/ufpmD7UIdD0FEOytJ6p1VKLQ7XdU=; b=cDXK04G7DbvVEbABnKyh9EEwXjo8SP/k6iPYLWWNubwgGISMf9IuWXVkID2h/neWdZ p6dfxM9hdlQ3oFhvIqTSk38oCY303rcI08EfHXJQqfurh07q+l+RDK43YOoFh/9EXgQK BptDSig83KjFeHs5D+bP/pQkYtm8m9zQYTXdYt2I+CTsUVc7w54os6jkN5jPPUysOUa5 XtZNoJF3o2o16NCpd0EFg/J+A7bK2ZfjqrGFAdGPJ+sqANqxQkeFQAGocrJjFtp66Xyn prUmMCFQ+O5x2zfkS/bo8yh/mffvG09tcJiJM7yqSbVcSJx/fxUUAq7tTxdZl0f36EhX tQYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=oLydZfU59BQFgQ/ufpmD7UIdD0FEOytJ6p1VKLQ7XdU=; b=hCA6SxA12FSvIVIqHZzEu1I1rLHdcaqnKEulChSuRgwQ3BNfxtfRFWNsk69vUWjv5o gThFqPMBnCZCW+WYiUws0ypoaZ39PfTrs/Aq3/JIFpdJAIP3qF80aPyx0wsF/fnVdV8U /IBO5n8vLqgPfAVFPcZIwjA1MrHgKYRtRjOuBhykc3AQV7aeD/BK+NSV5crRvutgRcvD S/S1XFovRQg+jOXbt7YH4l0jMKEYxYeT7cY+PNxPEaC6I8Iw5Eug1+kfxeJUIxD6qVb5 DR/4807UtSMXNHHa3h2vWKDebVfkSmXijK/9gQMwrvSnAqqUhz14fQPI1NeXaVdV8HUd zECA== X-Gm-Message-State: ACgBeo08z6R3zSPAVj7yTWBkNPfrmDcouFkAVPi0tfN66EYYAAN9ZyE1 NMV5TB5/z7+q43ZNpSuOE9MrKmcJLKd7QQ== X-Google-Smtp-Source: AA6agR7/Yh+gLdhjX0oZHdw7UAKTbhu2Ve+O5q+Qf9fzMhA3QlgEUeQ9nAGBIJqHUlgoDAWEUddBRA== X-Received: by 2002:a5d:59af:0:b0:226:ffd5:58d with SMTP id p15-20020a5d59af000000b00226ffd5058dmr8857919wrr.405.1662362757791; Mon, 05 Sep 2022 00:25:57 -0700 (PDT) Received: from poulhies-Precision-5550 (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id h18-20020a5d5052000000b002285fbc1c9asm5551809wrt.106.2022.09.05.00.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:25:57 -0700 (PDT) Date: Mon, 5 Sep 2022 09:25:56 +0200 From: Marc =?iso-8859-1?Q?Poulhi=E8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Cleanup analysis of quantified expressions with empty ranges Message-ID: <20220905072556.GA1174578@poulhies-Precision-5550> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="IS0zKkzwUGydFO0o" Content-Disposition: inline X-Spam-Status: No, score=-12.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 List-Id: --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Cleanup handling of quantified expressions before using it as an inspiration for fixing the handling of iterated component associations. Behavior is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch4.adb (Is_Empty_Range): Move error reporting to the caller. (Analyze_Qualified_Expression): Move error reporting from Is_Empty_Range; add matching call to End_Scope before rewriting and returning. --IS0zKkzwUGydFO0o Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -4394,9 +4394,8 @@ package body Sem_Ch4 is procedure Analyze_Quantified_Expression (N : Node_Id) is function Is_Empty_Range (Typ : Entity_Id) return Boolean; - -- If the iterator is part of a quantified expression, and the range is - -- known to be statically empty, emit a warning and replace expression - -- with its static value. Returns True if the replacement occurs. + -- Return True if the iterator is part of a quantified expression and + -- the range is known to be statically empty. function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean; -- Determine whether if expression If_Expr lacks an else part or if it @@ -4407,36 +4406,12 @@ package body Sem_Ch4 is -------------------- function Is_Empty_Range (Typ : Entity_Id) return Boolean is - Loc : constant Source_Ptr := Sloc (N); - begin - if Is_Array_Type (Typ) + return Is_Array_Type (Typ) and then Compile_Time_Known_Bounds (Typ) and then - (Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) > - Expr_Value (Type_High_Bound (Etype (First_Index (Typ))))) - then - Preanalyze_And_Resolve (Condition (N), Standard_Boolean); - - if All_Present (N) then - Error_Msg_N - ("??quantified expression with ALL " - & "over a null range has value True", N); - Rewrite (N, New_Occurrence_Of (Standard_True, Loc)); - - else - Error_Msg_N - ("??quantified expression with SOME " - & "over a null range has value False", N); - Rewrite (N, New_Occurrence_Of (Standard_False, Loc)); - end if; - - Analyze (N); - return True; - - else - return False; - end if; + Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) > + Expr_Value (Type_High_Bound (Etype (First_Index (Typ)))); end Is_Empty_Range; ----------------------------- @@ -4456,6 +4431,7 @@ package body Sem_Ch4 is -- Local variables Cond : constant Node_Id := Condition (N); + Loc : constant Source_Ptr := Sloc (N); Loop_Id : Entity_Id; QE_Scop : Entity_Id; @@ -4466,7 +4442,7 @@ package body Sem_Ch4 is -- expression. The scope is needed to provide proper visibility of the -- loop variable. - QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L'); + QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Loc, 'L'); Set_Etype (QE_Scop, Standard_Void_Type); Set_Scope (QE_Scop, Current_Scope); Set_Parent (QE_Scop, N); @@ -4482,11 +4458,30 @@ package body Sem_Ch4 is Preanalyze (Iterator_Specification (N)); -- Do not proceed with the analysis when the range of iteration is - -- empty. The appropriate error is issued by Is_Empty_Range. + -- empty. if Is_Entity_Name (Name (Iterator_Specification (N))) and then Is_Empty_Range (Etype (Name (Iterator_Specification (N)))) then + Preanalyze_And_Resolve (Condition (N), Standard_Boolean); + End_Scope; + + -- Emit a warning and replace expression with its static value + + if All_Present (N) then + Error_Msg_N + ("??quantified expression with ALL " + & "over a null range has value True", N); + Rewrite (N, New_Occurrence_Of (Standard_True, Loc)); + + else + Error_Msg_N + ("??quantified expression with SOME " + & "over a null range has value False", N); + Rewrite (N, New_Occurrence_Of (Standard_False, Loc)); + end if; + + Analyze (N); return; end if; --IS0zKkzwUGydFO0o--