[Ada] Set_Is_Known_Valid only if Safe_To_Capture_Value
authorAlexandre Oliva <oliva@adacore.com>
Wed, 29 Dec 2021 07:10:45 +0000 (04:10 -0300)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 11 May 2022 08:53:17 +0000 (08:53 +0000)
commit2749e4ab8fb74e43fc84724ef259589d75c121ff
tree4ba6aabb4b5fb97fa6f67a0891d1c2be817e5b96
parentd7ca4dfe8dc96c7e78a8fbfedda2558fca2aa277
[Ada] Set_Is_Known_Valid only if Safe_To_Capture_Value

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.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Guard
Set_Is_Known_Valid with Safe_To_Capture_Value.
gcc/ada/exp_ch3.adb