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 D3B0A383642C for ; Wed, 11 May 2022 08:54:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D3B0A383642C Received: by mail-wm1-x332.google.com with SMTP id i20-20020a05600c355400b0039456976dcaso2164695wmq.1 for ; Wed, 11 May 2022 01:54:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=0SN6obh0Ca/fvJ6Ep7Flt6mIkSOORekMhiOOREW591Q=; b=JfRV9PWBggmqrtx2j9bMFtO62bD7QOOCw9F8KH+5RiqESrZXbfHyq1RTaoci4iK/fX 8HOuELvDp83A5dzMuy8XvMSUSEVZQNegtyJpSPxOrT0mAFCqpX147r/M1KmUZjjROW9K D9jFyJcG8rDyGtty0tIkoHhjrHvOtf0+zUSctw8ECqnUYpGYqf8S7AuD1zQIVavhxEzb DU71v6SmjXGM5l7dgmGSD1cVF2gsX7KjE5BHazr9ODtA4LswLs9Vx6JBpOOKJhtZLaDk Om1nGmrKZCuL71Gjj68NFJPEN4z/aG2bV/LuqRRmh/71+HaznDWiasJiGfXGPbOR+bFc AjKQ== X-Gm-Message-State: AOAM531Pry8SXdy94ZrYvHtCcSPhzuKPxLm6Rjz72oI96KvB1X989Alt 9x6GYkwPpAxQECFgEX2RO16Ex/ObJIzL4w== X-Google-Smtp-Source: ABdhPJwUZ6odz6+bma0W5e/68hL+/IARLcydhIHY++AkUb9jutGvZ3uKfAD3eu2OwFLH6saFtRsFeA== X-Received: by 2002:a05:600c:1151:b0:394:6816:d4f2 with SMTP id z17-20020a05600c115100b003946816d4f2mr3708077wmz.195.1652259261550; Wed, 11 May 2022 01:54:21 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id t13-20020adff04d000000b0020ce015ed48sm491279wro.103.2022.05.11.01.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 01:54:21 -0700 (PDT) Date: Wed, 11 May 2022 08:54:20 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Alexandre Oliva Subject: [Ada] Set_Is_Known_Valid only if Safe_To_Capture_Value Message-ID: <20220511085420.GA2165939@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0OAP2g/MAC+5xKAE" Content-Disposition: inline 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Wed, 11 May 2022 08:54:24 -0000 --0OAP2g/MAC+5xKAE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Library-level variables with initializers could have Is_Known_Valid set when analyzing their definition, and the flag would only be cleared when analyzing a statement that assigned to them. Procedures and functions analyzed before the flag got cleared could skip validity checking for the corresponding variable. This patch fixes this problem: we no longer set Is_Known_Valid when analyzing initializers of library-level variables,and use the same Safe_To_Capture_Value predicate that prevents assignments from recording known-valid states. This causes any variable with an initialization value, that would have had its initializer value used as its known constant value if the use is analyzed before any assignment to the variable, to no longer be regarded as holding a constant value. Some might turn out to have a constant value, after all, but we don't know that yet: we can only tell after analyzing every subprogram that could possibly assign to it. At the points where Safe_To_Capture_Value calls are introduced, Never_Set_In_Source does not yet hold its final value. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch3.adb (Expand_N_Object_Declaration): Guard Set_Is_Known_Valid with Safe_To_Capture_Value. --0OAP2g/MAC+5xKAE Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb --- a/gcc/ada/exp_ch3.adb +++ b/gcc/ada/exp_ch3.adb @@ -7534,6 +7534,7 @@ package body Exp_Ch3 is elsif Comes_From_Source (N) and then Is_Discrete_Type (Typ) and then Expr_Known_Valid (Expr) + and then Safe_To_Capture_Value (N, Def_Id) then Set_Is_Known_Valid (Def_Id); @@ -7564,7 +7565,9 @@ package body Exp_Ch3 is and then not Is_Generic_Type (Etype (Def_Id)) then Ensure_Valid (Expr); - Set_Is_Known_Valid (Def_Id); + if Safe_To_Capture_Value (N, Def_Id) then + Set_Is_Known_Valid (Def_Id); + end if; end if; end if; --0OAP2g/MAC+5xKAE--