public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Alexandre Oliva <oliva@adacore.com>
Subject: [Ada] Set_Is_Known_Valid only if Safe_To_Capture_Value
Date: Wed, 11 May 2022 08:54:20 +0000	[thread overview]
Message-ID: <20220511085420.GA2165939@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1237 bytes --]

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.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 792 bytes --]

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;
 



                 reply	other threads:[~2022-05-11  8:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220511085420.GA2165939@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=oliva@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).