diff options
author | Bob Duff <duff@adacore.com> | 2018-11-14 11:41:36 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-11-14 11:41:36 +0000 |
commit | 1e3c434fa08b0ee0e4f9b5ce803e282d8832a559 (patch) | |
tree | 53c1e8aff76e28c94f53a22b6ebaf2c960a5812c /gcc/ada/sem_eval.adb | |
parent | 43018f5892ff43551abad3f339bcb55cf74c89cf (diff) | |
download | gcc-1e3c434fa08b0ee0e4f9b5ce803e282d8832a559.zip gcc-1e3c434fa08b0ee0e4f9b5ce803e282d8832a559.tar.gz gcc-1e3c434fa08b0ee0e4f9b5ce803e282d8832a559.tar.bz2 |
[Ada] System'To_Address not always static
System'To_Address is supposed to be static when its parameter is static.
This patch fixes a bug in which it is considered nonstatic when used as
the initial value of a variable with the Thread_Local_Storage aspect, so
the compiler incorrectly gives an error when initializing such a
variable with System'To_Address (0).
2018-11-14 Bob Duff <duff@adacore.com>
gcc/ada/
* sem_attr.adb (To_Address): Simplify setting of
Is_Static_Expression. Remove second (unconditional) call to
Set_Is_Static_Expression -- surely it's not static if the
operand is not. Initialize Static on declaration. Do not try
to fold 'To_Address, even though it's static.
* exp_attr.adb (To_Address): Preserve Is_Static_Expression.
* sinfo.ads, sem_eval.ads, sem_eval.adb (Is_Static_Expression,
Is_OK_Static_Expression, Raises_Constraint_Error): Simplify
documentation. There was too much repetition and redundancy.
From-SVN: r266124
Diffstat (limited to 'gcc/ada/sem_eval.adb')
-rw-r--r-- | gcc/ada/sem_eval.adb | 84 |
1 files changed, 38 insertions, 46 deletions
diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index 4560a51..ec98a3a 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -66,33 +66,25 @@ package body Sem_Eval is -- a subexpression is resolved and is therefore accomplished in a bottom -- up fashion. The flags are synthesized using the following approach. - -- Is_Static_Expression is determined by following the detailed rules - -- in RM 4.9(4-14). This involves testing the Is_Static_Expression - -- flag of the operands in many cases. - - -- Raises_Constraint_Error is set if any of the operands have the flag - -- set or if an attempt to compute the value of the current expression - -- results in detection of a runtime constraint error. - - -- As described in the spec, the requirement is that Is_Static_Expression - -- be accurately set, and in addition for nodes for which this flag is set, - -- Raises_Constraint_Error must also be set. Furthermore a node which has - -- Is_Static_Expression set, and Raises_Constraint_Error clear, then the - -- requirement is that the expression value must be precomputed, and the - -- node is either a literal, or the name of a constant entity whose value - -- is a static expression. + -- Is_Static_Expression is determined by following the rules in + -- RM-4.9. This involves testing the Is_Static_Expression flag of + -- the operands in many cases. + + -- Raises_Constraint_Error is usually set if any of the operands have + -- the flag set or if an attempt to compute the value of the current + -- expression results in Constraint_Error. -- The general approach is as follows. First compute Is_Static_Expression. -- If the node is not static, then the flag is left off in the node and -- we are all done. Otherwise for a static node, we test if any of the - -- operands will raise constraint error, and if so, propagate the flag + -- operands will raise Constraint_Error, and if so, propagate the flag -- Raises_Constraint_Error to the result node and we are done (since the -- error was already posted at a lower level). -- For the case of a static node whose operands do not raise constraint -- error, we attempt to evaluate the node. If this evaluation succeeds, -- then the node is replaced by the result of this computation. If the - -- evaluation raises constraint error, then we rewrite the node with + -- evaluation raises Constraint_Error, then we rewrite the node with -- Apply_Compile_Time_Constraint_Error to raise the exception and also -- to post appropriate error messages. @@ -108,7 +100,7 @@ package body Sem_Eval is -- discrete types (the most common case), and is populated by calls to -- Compile_Time_Known_Value and Expr_Value, but only used by Expr_Value -- since it is possible for the status to change (in particular it is - -- possible for a node to get replaced by a constraint error node). + -- possible for a node to get replaced by a Constraint_Error node). CV_Bits : constant := 5; -- Number of low order bits of Node_Id value used to reference entries @@ -295,8 +287,8 @@ package body Sem_Eval is -- If either operand is Any_Type then propagate it to result to prevent -- cascaded errors. -- - -- If some operand raises constraint error, then replace the node N - -- with the raise constraint error node. This replacement inherits the + -- If some operand raises Constraint_Error, then replace the node N + -- with the raise Constraint_Error node. This replacement inherits the -- Is_Static_Expression flag from the operands. procedure Test_Expression_Is_Foldable @@ -1129,7 +1121,7 @@ package body Sem_Eval is return Unknown; end if; - -- If either operand could raise constraint error, then we cannot + -- If either operand could raise Constraint_Error, then we cannot -- know the result at compile time (since CE may be raised). if not (Cannot_Raise_Constraint_Error (L) @@ -1696,7 +1688,7 @@ package body Sem_Eval is CV_Ent : CV_Entry renames CV_Cache (Nat (Op) mod CV_Cache_Size); begin - -- Never known at compile time if bad type or raises constraint error + -- Never known at compile time if bad type or raises Constraint_Error -- or empty (latter case occurs only as a result of a previous error). if No (Op) then @@ -2201,7 +2193,7 @@ package body Sem_Eval is end if; -- First loop, make sure all the alternatives are static expressions - -- none of which raise Constraint_Error. We make the constraint error + -- none of which raise Constraint_Error. We make the Constraint_Error -- check because part of the legality condition for a correct static -- case expression is that the cases are covered, like any other case -- expression. And we can't do that if any of the conditions raise an @@ -2237,7 +2229,7 @@ package body Sem_Eval is Set_Is_Static_Expression (N); - -- Now to deal with propagating a possible constraint error + -- Now to deal with propagating a possible Constraint_Error -- If the selecting expression raises CE, propagate and we are done @@ -2408,7 +2400,7 @@ package body Sem_Eval is begin -- Enumeration literals are always considered to be constants - -- and cannot raise constraint error (RM 4.9(22)). + -- and cannot raise Constraint_Error (RM 4.9(22)). if Ekind (Def_Id) = E_Enumeration_Literal then Set_Is_Static_Expression (N); @@ -2506,7 +2498,7 @@ package body Sem_Eval is return; end if; - -- If condition raises constraint error then we have already signaled + -- If condition raises Constraint_Error then we have already signaled -- an error, and we just propagate to the result and do not fold. if Raises_Constraint_Error (Condition) then @@ -2531,8 +2523,8 @@ package body Sem_Eval is end if; -- Note that it does not matter if the non-result operand raises a - -- Constraint_Error, but if the result raises constraint error then we - -- replace the node with a raise constraint error. This will properly + -- Constraint_Error, but if the result raises Constraint_Error then we + -- replace the node with a raise Constraint_Error. This will properly -- propagate Raises_Constraint_Error since this flag is set in Result. if Raises_Constraint_Error (Result) then @@ -2884,7 +2876,7 @@ package body Sem_Eval is Set_Is_Static_Expression (N); - -- If left operand raises constraint error, propagate and we are done + -- If left operand raises Constraint_Error, propagate and we are done if Raises_Constraint_Error (Expr) then Set_Raises_Constraint_Error (N, True); @@ -3117,7 +3109,7 @@ package body Sem_Eval is if not Fold then return; - -- Don't try fold if target type has constraint error bounds + -- Don't try fold if target type has Constraint_Error bounds elsif not Is_OK_Static_Subtype (Target_Type) then Set_Raises_Constraint_Error (N); @@ -3645,7 +3637,7 @@ package body Sem_Eval is -- Now look at the operands, we can't quite use the normal call to -- Test_Expression_Is_Foldable here because short circuit operations -- are a special case, they can still be foldable, even if the right - -- operand raises constraint error. + -- operand raises Constraint_Error. -- If either operand is Any_Type, just propagate to result and do not -- try to fold, this prevents cascaded errors. @@ -3654,8 +3646,8 @@ package body Sem_Eval is Set_Etype (N, Any_Type); return; - -- If left operand raises constraint error, then replace node N with - -- the raise constraint error node, and we are obviously not foldable. + -- If left operand raises Constraint_Error, then replace node N with + -- the raise Constraint_Error node, and we are obviously not foldable. -- Is_Static_Expression is set from the two operands in the normal way, -- and we check the right operand if it is in a non-static context. @@ -3678,12 +3670,12 @@ package body Sem_Eval is -- Here the result is static, note that, unlike the normal processing -- in Test_Expression_Is_Foldable, we did *not* check above to see if - -- the right operand raises constraint error, that's because it is not + -- the right operand raises Constraint_Error, that's because it is not -- significant if the left operand is decisive. Set_Is_Static_Expression (N); - -- It does not matter if the right operand raises constraint error if + -- It does not matter if the right operand raises Constraint_Error if -- it will not be evaluated. So deal specially with the cases where -- the right operand is not evaluated. Note that we will fold these -- cases even if the right operand is non-static, which is fine, but @@ -3700,7 +3692,7 @@ package body Sem_Eval is end if; -- If first operand not decisive, then it does matter if the right - -- operand raises constraint error, since it will be evaluated, so + -- operand raises Constraint_Error, since it will be evaluated, so -- we simply replace the node with the right operand. Note that this -- properly propagates Is_Static_Expression and Raises_Constraint_Error -- (both are set to True in Right). @@ -3951,7 +3943,7 @@ package body Sem_Eval is if not Fold then return; - -- Don't try fold if target type has constraint error bounds + -- Don't try fold if target type has Constraint_Error bounds elsif not Is_OK_Static_Subtype (Target_Type) then Set_Raises_Constraint_Error (N); @@ -4915,7 +4907,7 @@ package body Sem_Eval is -------------------------- -- Determines if Typ is a static subtype as defined in (RM 4.9(26)) where - -- neither bound raises constraint error when evaluated. + -- neither bound raises Constraint_Error when evaluated. function Is_OK_Static_Subtype (Typ : Entity_Id) return Boolean is Base_T : constant Entity_Id := Base_Type (Typ); @@ -6044,7 +6036,7 @@ package body Sem_Eval is then return False; - -- If either expression raised a constraint error, + -- If either expression raised a Constraint_Error, -- consider the expressions as matching, since this -- helps to prevent cascading errors. @@ -6255,8 +6247,8 @@ package body Sem_Eval is Set_Etype (N, Any_Type); return; - -- If operand raises constraint error, then replace node N with the - -- raise constraint error node, and we are obviously not foldable. + -- If operand raises Constraint_Error, then replace node N with the + -- raise Constraint_Error node, and we are obviously not foldable. -- Note that this replacement inherits the Is_Static_Expression flag -- from the operand. @@ -6283,7 +6275,7 @@ package body Sem_Eval is return; -- Here we have the case of an operand whose type is OK, which is - -- static, and which does not raise constraint error, we can fold. + -- static, and which does not raise Constraint_Error, we can fold. else Set_Is_Static_Expression (N); @@ -6323,7 +6315,7 @@ package body Sem_Eval is Set_Etype (N, Any_Type); return; - -- If left operand raises constraint error, then replace node N with the + -- If left operand raises Constraint_Error, then replace node N with the -- Raise_Constraint_Error node, and we are obviously not foldable. -- Is_Static_Expression is set from the two operands in the normal way, -- and we check the right operand if it is in a non-static context. @@ -6376,7 +6368,7 @@ package body Sem_Eval is return; -- Else result is static and foldable. Both operands are static, and - -- neither raises constraint error, so we can definitely fold. + -- neither raises Constraint_Error, so we can definitely fold. else Set_Is_Static_Expression (N); @@ -6413,7 +6405,7 @@ package body Sem_Eval is if Error_Posted (N) then return Unknown; - -- Expression that raises constraint error is an odd case. We certainly + -- Expression that raises Constraint_Error is an odd case. We certainly -- do not want to consider it to be in range. It might make sense to -- consider it always out of range, but this causes incorrect error -- messages about static expressions out of range. So we just return @@ -6601,7 +6593,7 @@ package body Sem_Eval is return; end if; - -- Test for constraint error raised + -- Test for Constraint_Error raised if Raises_Constraint_Error (Expr) then |