mirror of git://gcc.gnu.org/git/gcc.git
[multiple changes]
2017-01-06 Ed Schonberg <schonberg@adacore.com> * sem_eval.adb (Check_Expression_Against_Static_Predicate): If expression is compile-time known and obeys a static predicate it must be labelled as static, to prevent spurious warnings and run-time errors, e.g. in case statements. This is relevant when the expression is the result of constant-folding a type conversion whose expression is a variable with a known static value. 2017-01-06 Hristian Kirtchev <kirtchev@adacore.com> * exp_attr.adb, sem_attr.ads: Minor reformatting. From-SVN: r244135
This commit is contained in:
parent
f68d33443e
commit
d9c59db455
|
|
@ -1,3 +1,16 @@
|
||||||
|
2017-01-06 Ed Schonberg <schonberg@adacore.com>
|
||||||
|
|
||||||
|
* sem_eval.adb (Check_Expression_Against_Static_Predicate):
|
||||||
|
If expression is compile-time known and obeys a static predicate
|
||||||
|
it must be labelled as static, to prevent spurious warnings and
|
||||||
|
run-time errors, e.g. in case statements. This is relevant when
|
||||||
|
the expression is the result of constant-folding a type conversion
|
||||||
|
whose expression is a variable with a known static value.
|
||||||
|
|
||||||
|
2017-01-06 Hristian Kirtchev <kirtchev@adacore.com>
|
||||||
|
|
||||||
|
* exp_attr.adb, sem_attr.ads: Minor reformatting.
|
||||||
|
|
||||||
2017-01-06 Justin Squirek <squirek@adacore.com>
|
2017-01-06 Justin Squirek <squirek@adacore.com>
|
||||||
|
|
||||||
* exp_attr.adb (Expand_N_Attribute_Reference): Add entry for
|
* exp_attr.adb (Expand_N_Attribute_Reference): Add entry for
|
||||||
|
|
|
||||||
|
|
@ -3141,11 +3141,10 @@ package body Exp_Attr is
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
when Attribute_Finalization_Size => Finalization_Size : declare
|
when Attribute_Finalization_Size => Finalization_Size : declare
|
||||||
|
|
||||||
function Calculate_Header_Size return Node_Id;
|
function Calculate_Header_Size return Node_Id;
|
||||||
-- Generate a runtime call to calculate the size of the hidden
|
-- Generate a runtime call to calculate the size of the hidden header
|
||||||
-- header along with any added padding which would precede a
|
-- along with any added padding which would precede a heap-allocated
|
||||||
-- heap-allocated object of the prefix type.
|
-- object of the prefix type.
|
||||||
|
|
||||||
---------------------------
|
---------------------------
|
||||||
-- Calculate_Header_Size --
|
-- Calculate_Header_Size --
|
||||||
|
|
@ -3155,34 +3154,33 @@ package body Exp_Attr is
|
||||||
begin
|
begin
|
||||||
-- Generate:
|
-- Generate:
|
||||||
-- Universal_Integer
|
-- Universal_Integer
|
||||||
-- (Header_Size_With_Padding (N'Alignment))
|
-- (Header_Size_With_Padding (Pref'Alignment))
|
||||||
|
|
||||||
return
|
return
|
||||||
Convert_To (Universal_Integer,
|
Convert_To (Universal_Integer,
|
||||||
Make_Function_Call (Loc,
|
Make_Function_Call (Loc,
|
||||||
Name =>
|
Name =>
|
||||||
New_Occurrence_Of
|
New_Occurrence_Of (RTE (RE_Header_Size_With_Padding), Loc),
|
||||||
(RTE (RE_Header_Size_With_Padding), Loc),
|
|
||||||
Parameter_Associations => New_List (
|
Parameter_Associations => New_List (
|
||||||
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
||||||
Prefix =>
|
Prefix => New_Copy_Tree (Pref),
|
||||||
New_Copy_Tree (Pref),
|
|
||||||
Attribute_Name => Name_Alignment))));
|
Attribute_Name => Name_Alignment))));
|
||||||
end Calculate_Header_Size;
|
end Calculate_Header_Size;
|
||||||
|
|
||||||
-- Local variables
|
-- Local variables
|
||||||
|
|
||||||
Size : constant Entity_Id := Make_Temporary (Loc, 'S');
|
Size : Entity_Id;
|
||||||
|
|
||||||
-- Start of Finalization_Size
|
-- Start of Finalization_Size
|
||||||
|
|
||||||
begin
|
begin
|
||||||
-- An object of a class-wide type requires a runtime check to
|
-- An object of a class-wide type first requires a runtime check to
|
||||||
-- determine whether it is actually controlled or not. Depending on
|
-- determine whether it is actually controlled or not. Depending on
|
||||||
-- the outcome of this check, the Finalization_Size of the object
|
-- the outcome of this check, the Finalization_Size of the object
|
||||||
-- may be zero or some positive value.
|
-- may be zero or some positive value.
|
||||||
--
|
--
|
||||||
-- In this scenario, Obj'Finalization_Size is expanded into
|
-- In this scenario, Pref'Finalization_Size is expanded into
|
||||||
--
|
--
|
||||||
-- Size : Integer := 0;
|
-- Size : Integer := 0;
|
||||||
--
|
--
|
||||||
|
|
@ -3195,6 +3193,8 @@ package body Exp_Attr is
|
||||||
-- and the attribute reference is replaced with a reference to Size.
|
-- and the attribute reference is replaced with a reference to Size.
|
||||||
|
|
||||||
if Is_Class_Wide_Type (Ptyp) then
|
if Is_Class_Wide_Type (Ptyp) then
|
||||||
|
Size := Make_Temporary (Loc, 'S');
|
||||||
|
|
||||||
Insert_Actions (N, New_List (
|
Insert_Actions (N, New_List (
|
||||||
|
|
||||||
-- Generate:
|
-- Generate:
|
||||||
|
|
@ -3208,7 +3208,8 @@ package body Exp_Attr is
|
||||||
|
|
||||||
-- Generate:
|
-- Generate:
|
||||||
-- if Needs_Finalization (Pref'Tag) then
|
-- if Needs_Finalization (Pref'Tag) then
|
||||||
-- Size := Universal_Integer
|
-- Size :=
|
||||||
|
-- Universal_Integer
|
||||||
-- (Header_Size_With_Padding (Pref'Alignment));
|
-- (Header_Size_With_Padding (Pref'Alignment));
|
||||||
-- end if;
|
-- end if;
|
||||||
|
|
||||||
|
|
@ -3216,13 +3217,13 @@ package body Exp_Attr is
|
||||||
Condition =>
|
Condition =>
|
||||||
Make_Function_Call (Loc,
|
Make_Function_Call (Loc,
|
||||||
Name =>
|
Name =>
|
||||||
New_Occurrence_Of
|
New_Occurrence_Of (RTE (RE_Needs_Finalization), Loc),
|
||||||
(RTE (RE_Needs_Finalization), Loc),
|
|
||||||
Parameter_Associations => New_List (
|
Parameter_Associations => New_List (
|
||||||
Make_Attribute_Reference (Loc,
|
Make_Attribute_Reference (Loc,
|
||||||
Attribute_Name => Name_Tag,
|
Prefix => New_Copy_Tree (Pref),
|
||||||
Prefix =>
|
Attribute_Name => Name_Tag))),
|
||||||
New_Copy_Tree (Pref)))),
|
|
||||||
Then_Statements => New_List (
|
Then_Statements => New_List (
|
||||||
Make_Assignment_Statement (Loc,
|
Make_Assignment_Statement (Loc,
|
||||||
Name => New_Occurrence_Of (Size, Loc),
|
Name => New_Occurrence_Of (Size, Loc),
|
||||||
|
|
@ -3230,15 +3231,14 @@ package body Exp_Attr is
|
||||||
|
|
||||||
Rewrite (N, New_Occurrence_Of (Size, Loc));
|
Rewrite (N, New_Occurrence_Of (Size, Loc));
|
||||||
|
|
||||||
-- The the prefix is known to be controlled at compile time.
|
-- The prefix is known to be controlled at compile time. Calculate
|
||||||
-- Calculate its Finalization_Size by calling runtime routine
|
-- Finalization_Size by calling function Header_Size_With_Padding.
|
||||||
-- Header_Size_With_Padding.
|
|
||||||
|
|
||||||
elsif Needs_Finalization (Ptyp) then
|
elsif Needs_Finalization (Ptyp) then
|
||||||
Rewrite (N, Calculate_Header_Size);
|
Rewrite (N, Calculate_Header_Size);
|
||||||
|
|
||||||
-- The prefix is not a controlled object, its Finalization_Size
|
-- The prefix is not an object with controlled parts, so its
|
||||||
-- is zero.
|
-- Finalization_Size is zero.
|
||||||
|
|
||||||
else
|
else
|
||||||
Rewrite (N, Make_Integer_Literal (Loc, 0));
|
Rewrite (N, Make_Integer_Literal (Loc, 0));
|
||||||
|
|
|
||||||
|
|
@ -247,10 +247,10 @@ package Sem_Attr is
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
Attribute_Finalization_Size => True,
|
Attribute_Finalization_Size => True,
|
||||||
-- For every object, Finalization_Size will return the size of the
|
-- For every object, Finalization_Size returns the size of the hidden
|
||||||
-- internal header required for finalization (including padding). If
|
-- header used for finalization purposes as if the object was allocated
|
||||||
-- the type is not controlled or contains no controlled components
|
-- on the heap. The size of the header does take into account any extra
|
||||||
-- then the result is always zero.
|
-- padding due to alignment issues.
|
||||||
|
|
||||||
-----------------
|
-----------------
|
||||||
-- Fixed_Value --
|
-- Fixed_Value --
|
||||||
|
|
|
||||||
|
|
@ -347,7 +347,11 @@ package body Sem_Eval is
|
||||||
|
|
||||||
-- Here we have a static predicate (note that it could have arisen from
|
-- Here we have a static predicate (note that it could have arisen from
|
||||||
-- an explicitly specified Dynamic_Predicate whose expression met the
|
-- an explicitly specified Dynamic_Predicate whose expression met the
|
||||||
-- rules for being predicate-static).
|
-- rules for being predicate-static). If the expression is known at
|
||||||
|
-- compile time and obeys the predicate, then it is static and must be
|
||||||
|
-- labeled as such, which matters e.g. for case statements. The original
|
||||||
|
-- expression may be a type conversion of a variable with a known value,
|
||||||
|
-- which might otherwise not be marked static.
|
||||||
|
|
||||||
-- Case of real static predicate
|
-- Case of real static predicate
|
||||||
|
|
||||||
|
|
@ -356,6 +360,7 @@ package body Sem_Eval is
|
||||||
(Val => Make_Real_Literal (Sloc (Expr), Expr_Value_R (Expr)),
|
(Val => Make_Real_Literal (Sloc (Expr), Expr_Value_R (Expr)),
|
||||||
Typ => Typ)
|
Typ => Typ)
|
||||||
then
|
then
|
||||||
|
Set_Is_Static_Expression (Expr);
|
||||||
return;
|
return;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
|
|
@ -365,6 +370,7 @@ package body Sem_Eval is
|
||||||
if Real_Or_String_Static_Predicate_Matches
|
if Real_Or_String_Static_Predicate_Matches
|
||||||
(Val => Expr_Value_S (Expr), Typ => Typ)
|
(Val => Expr_Value_S (Expr), Typ => Typ)
|
||||||
then
|
then
|
||||||
|
Set_Is_Static_Expression (Expr);
|
||||||
return;
|
return;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
|
|
@ -376,6 +382,7 @@ package body Sem_Eval is
|
||||||
-- If static predicate matches, nothing to do
|
-- If static predicate matches, nothing to do
|
||||||
|
|
||||||
if Choices_Match (Expr, Static_Discrete_Predicate (Typ)) = Match then
|
if Choices_Match (Expr, Static_Discrete_Predicate (Typ)) = Match then
|
||||||
|
Set_Is_Static_Expression (Expr);
|
||||||
return;
|
return;
|
||||||
end if;
|
end if;
|
||||||
end if;
|
end if;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue