From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 133303839DDA for ; Thu, 6 Oct 2022 09:29:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 133303839DDA 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-wm1-x332.google.com with SMTP id v130-20020a1cac88000000b003bcde03bd44so2426478wme.5 for ; Thu, 06 Oct 2022 02:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5uo2mQOR+Py1VghgsM5GNn4NxoNBAKMVdmLSGDd9luw=; b=iVJEeKI5p3V2rlWmxsMRH9G8lIeZG9P86GhKkhw65iCrDImGcmCKhOX6T3lgns7eJC NaWepDnAYX5lf3iBMcDnvpkQ7EJbvs2s5P6C0CemPy7u2XMWKUjrNWOLCE0vz9jS2YC7 z9hCeb/0KPCNntZr8zFUUVRpnF/Zub8CUo4G0PbC7A9+IWXvbKNkidYFgX8olCzYtA/e WyU7UUjB/vVPsZLzKt/GwCCGeW8s7tbWUh43RezwoxSrqnLvSC/dMB4rdjKrH+KmI8d+ b+w7uRt+vpIQZiXkfksYaLxavFt8tk0G7ExzDOtB3GixDap1ES9h1q4KrleQ6p9erPdX K3KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=5uo2mQOR+Py1VghgsM5GNn4NxoNBAKMVdmLSGDd9luw=; b=7CwTCoXMkE7rnldEr16sJi+6EvjzRMeLu9a7ysjfSsOsVsi5cB9AmQHHD08XTkbg15 yld/7y2Qsh9/pMrGE8cXxx/jPfOpVgPyCDX8tMk7cxB6dQWs0GjMgCMLzPuqM7QYkTxR +hdJ1pgm1L0aPcVB24CZ5BRDEAZfziP1L9k+ziEZufuZ58KehZb8ZEh8+ozKZtizCsNx 1AHrnZd4pcCGmKml6bRuG/xrc3M4tZHDO6LqhYfs21VJCE7M4sWLz+yuCYGpMEn5nBaV 6hIZNi8gLa2WfLdz/6dP5oc11ohqD7bRLbi9YfqJgj2or0uBQxol3GX12PJMniewTNor lU4Q== X-Gm-Message-State: ACrzQf1BvTAnw29pk2Y/BSnbWFcS1cGJKXkg1XkL0ZPa5QvGLpl83vMO Bxm4QX7rjNRjVevqp5zx+t8zV97FDPFmqoiS X-Google-Smtp-Source: AMsMyM4FuOwbHQKWhPusgNeZn9XxTiFg7p4hg0IlTMy7NyX5BO9gUgYsetR5VkJlEiKq3aa3gCni3Q== X-Received: by 2002:a05:600c:4c96:b0:3b5:52d6:1573 with SMTP id g22-20020a05600c4c9600b003b552d61573mr6232375wmp.9.1665048579847; Thu, 06 Oct 2022 02:29:39 -0700 (PDT) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id a14-20020adfed0e000000b0022ae4f8395dsm17007545wro.96.2022.10.06.02.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 02:29:39 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [COMMITED] ada: Incorrect inferences drawn from if/elsif/while conditions with -gnatVo Date: Thu, 6 Oct 2022 11:29:29 +0200 Message-Id: <20221006092929.261152-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.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 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: Steve Baird Within the first (respectively, second) statement list of this if statement declare X : constant Integer := ... ; begin if X > 0 then ...; else ...; end if; end; we can safely assume that X is greater (respectively, not greater) than 0. Fix a bug that incorrectly computed the region in which such assumptions can be made to include the condition of the if-statement. This bug usually had no effect because semantic analysis/simplification of the condition was already complete before the code containing the bug was executed. Unfortunately, this is not true in some cases involving -gnatVo validity checking. In these cases, the bug could result in incorrect simplification of the condition at compile time. This, in turn, could lead to incorrect unconditional execution of one arm of the if-statement at run time. Similar errors appear to be possible for the conditions of an elsif or a while loop; the fix addresses these cases as well, although corresponding problems with these constructs have not been demonstrated. gcc/ada/ * exp_util.adb (Get_Current_Value_Condition): Treat references occurring within the condition of an if statement, an elsif, or a while loop in the same way as references that occur before the start of that enclosing construct. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_util.adb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 61395adf195..f569d2ef583 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -6923,6 +6923,11 @@ package body Exp_Util is if Loc < Sloc (CV) then return; + -- In condition of IF statement + + elsif In_Subtree (N => Var, Root => Condition (CV)) then + return; + -- After end of IF statement elsif Loc >= Sloc (CV) + Text_Ptr (UI_To_Int (End_Span (CV))) then @@ -7009,7 +7014,12 @@ package body Exp_Util is if Loc < Sloc (CV) then return; - -- After end of IF statement + -- In condition of ELSIF part + + elsif In_Subtree (N => Var, Root => Condition (CV)) then + return; + + -- After end of IF statement elsif Loc >= Sloc (Stm) + Text_Ptr (UI_To_Int (End_Span (Stm))) @@ -7066,6 +7076,11 @@ package body Exp_Util is if Loc < Sloc (Loop_Stmt) then return; + -- In condition of while loop + + elsif In_Subtree (N => Var, Root => Condition (CV)) then + return; + -- After end of LOOP statement elsif Loc >= Sloc (End_Label (Loop_Stmt)) then -- 2.34.1