From patchwork Mon Sep 5 07:25:56 2022 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: 967 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp56953wrt; Mon, 5 Sep 2022 00:29:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR7p0wP4aFVp2t6h7n4WxQ4E0KlF7cvBcXPVx7tjqb+P3Bk6mhsc3Ud8wdfrfaUHSpzZrv50 X-Received: by 2002:a17:907:7fac:b0:741:4247:d856 with SMTP id qk44-20020a1709077fac00b007414247d856mr27958436ejc.565.1662362996344; Mon, 05 Sep 2022 00:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662362996; cv=none; d=google.com; s=arc-20160816; b=ACdRDYbZuRQQoB6fTB1Shr9kJrD3a1h8Go0aWbde3Bq7vmUgnwSXFqIeOxW+W5dsph faqs2d7bVZpxk090V0oYMoyI+bNi6QzvOpKoIL2n+Ys2bSG06gchly46N2ZuKHJv2GEE NqAkdU4YlVgFjn+u3fF+Yfdt6oY+XPKEHOGOIxcpHIeeE0KOEEF5aJI/yCoifrktP12I pUZud3lctCsTr30wjyD9DQ62vPQwwJTBJzai7iqMiR8iYwt8ayoW1x82X7vETui48qeV FfsDBuzqJsOkxb6Dt3Mvr/BjQbbRMfZpzsec9CNrnv+hmZUxChsFPLf1yP+aaFAsIC/2 3RlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oLydZfU59BQFgQ/ufpmD7UIdD0FEOytJ6p1VKLQ7XdU=; b=pjCQ+y+NsskYPbMh1OtjTnzn/avUIgFWDOGf2x669xezuy/uB4FA7YcRGUmjoHRD1s Z0h1YE7kpjCHyIIiscpNibVP/Z2Ew5q+VqwQ8K5iXDWg5wZ5CoCMAF308EfDtiVUDmGy 4v/7EvpD6OWxyBmxH6bu/xMNUsX1gOEHI8ZVkdedaiQ4Ts42FM40S0DhitA6Cfw9NNm7 V0JgJSUcRcInk0SeWNBkqmU1P1pl6IcUodETV+aH+WQ2PlJmxTXAkecO4C0/U7NS4oz1 HITVFwvMcq5BhWNEIb6gjPOENf92HZRgoB8a6wJ8Yg4w8eQZCduVLzvt/U3/mmTttAh/ ii4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Rw29f3fV; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l13-20020a170906794d00b0073d328f840fsi8081325ejo.51.2022.09.05.00.29.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 00:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Rw29f3fV; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 D1044385357B for ; Mon, 5 Sep 2022 07:27:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1044385357B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662362874; bh=oLydZfU59BQFgQ/ufpmD7UIdD0FEOytJ6p1VKLQ7XdU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Rw29f3fVmy1kEw0/bOnrohFhc6BBsRD76grpJCKcoifbOv1j6k4NA28kfd8zuFZOb 1f/CFqV27xwcAZFBWFQ8MQtgNt2dpEXgV3qN82NhQF5ziGaWd3mDouDKhb3/c2DDUE VKGwq17jZBIx1/OrwAeJuE2DzroRkfLNYxcciHVk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 Received: by mail-wr1-x430.google.com with SMTP id e13so10100406wrm.1 for ; Mon, 05 Sep 2022 00:25:58 -0700 (PDT) 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-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 To: gcc-patches@gcc.gnu.org Subject: [Ada] Cleanup analysis of quantified expressions with empty ranges Message-ID: <20220905072556.GA1174578@poulhies-Precision-5550> MIME-Version: 1.0 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 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: Marc =?iso-8859-1?q?Poulhi=E8s?= Cc: Piotr Trojanek 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?1743113941196291264?= X-GMAIL-MSGID: =?utf-8?q?1743113941196291264?= 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. 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;