Commit 6188f4bd by Ed Schonberg Committed by Arnaud Charlet

sem_prag.adb (Analyze_Pragma, [...]): pre-analyze expression with type Any_Priority.

2013-04-11  Ed Schonberg  <schonberg@adacore.com>

	* sem_prag.adb (Analyze_Pragma, case Priority): pre-analyze
	expression with type Any_Priority.
	* exp_ch9.adb (Initialize_Protection): Check that the value
	of the priority expression is within the bounds of the proper
	priority type.

From-SVN: r197799
parent fce68ebe
2013-04-11 Ed Schonberg <schonberg@adacore.com>
* sem_prag.adb (Analyze_Pragma, case Priority): pre-analyze
expression with type Any_Priority.
* exp_ch9.adb (Initialize_Protection): Check that the value
of the priority expression is within the bounds of the proper
priority type.
2013-04-11 Robert Dewar <dewar@adacore.com> 2013-04-11 Robert Dewar <dewar@adacore.com>
* sem_prag.adb, prj-env.adb: Minor reformatting. * sem_prag.adb, prj-env.adb: Minor reformatting.
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1992-2012, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -13388,6 +13388,7 @@ package body Exp_Ch9 is ...@@ -13388,6 +13388,7 @@ package body Exp_Ch9 is
Args : List_Id; Args : List_Id;
L : constant List_Id := New_List; L : constant List_Id := New_List;
Has_Entry : constant Boolean := Has_Entries (Ptyp); Has_Entry : constant Boolean := Has_Entries (Ptyp);
Prio_Type : Entity_Id;
Restricted : constant Boolean := Restricted_Profile; Restricted : constant Boolean := Restricted_Profile;
begin begin
...@@ -13456,18 +13457,37 @@ package body Exp_Ch9 is ...@@ -13456,18 +13457,37 @@ package body Exp_Ch9 is
Expression Expression
(First (Pragma_Argument_Associations (Prio_Clause))); (First (Pragma_Argument_Associations (Prio_Clause)));
-- Get_Rep_Item returns either priority pragma.
if Pragma_Name (Prio_Clause) = Name_Priority then
Prio_Type := RTE (RE_Any_Priority);
else
Prio_Type := RTE (RE_Interrupt_Priority);
end if;
-- Attribute definition clause Priority -- Attribute definition clause Priority
else else
if Chars (Prio_Clause) = Name_Priority then
Prio_Type := RTE (RE_Any_Priority);
else
Prio_Type := RTE (RE_Interrupt_Priority);
end if;
Prio := Expression (Prio_Clause); Prio := Expression (Prio_Clause);
end if; end if;
-- If priority is a static expression, then we can duplicate it -- If priority is a static expression, then we can duplicate it
-- with no problem and simply append it to the argument list. -- with no problem and simply append it to the argument list.
-- However, it has only be pre-analyzed, so we need to check
-- now that it is in the bounds of the priority type.
if Is_Static_Expression (Prio) then if Is_Static_Expression (Prio) then
Set_Analyzed (Prio, False);
Append_To (Args, Append_To (Args,
Duplicate_Subexpr_No_Checks (Prio)); Make_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Prio_Type, Loc),
Expression => Duplicate_Subexpr (Prio)));
-- Otherwise, the priority may be a per-object expression, if -- Otherwise, the priority may be a per-object expression, if
-- it depends on a discriminant of the type. In this case, -- it depends on a discriminant of the type. In this case,
...@@ -13477,18 +13497,13 @@ package body Exp_Ch9 is ...@@ -13477,18 +13497,13 @@ package body Exp_Ch9 is
-- appropriate approach, but that could generate declarations -- appropriate approach, but that could generate declarations
-- improperly placed in the enclosing scope. -- improperly placed in the enclosing scope.
-- Note: Use System.Any_Priority as the expected type for the
-- non-static priority expression, in case the expression has
-- not been analyzed yet (as occurs for example with pragma
-- Interrupt_Priority).
else else
Temp := Make_Temporary (Loc, 'R', Prio); Temp := Make_Temporary (Loc, 'R', Prio);
Append_To (L, Append_To (L,
Make_Object_Declaration (Loc, Make_Object_Declaration (Loc,
Defining_Identifier => Temp, Defining_Identifier => Temp,
Object_Definition => Object_Definition =>
New_Occurrence_Of (RTE (RE_Any_Priority), Loc), New_Occurrence_Of (Prio_Type, Loc),
Expression => Relocate_Node (Prio))); Expression => Relocate_Node (Prio)));
Append_To (Args, New_Occurrence_Of (Temp, Loc)); Append_To (Args, New_Occurrence_Of (Temp, Loc));
......
...@@ -14521,7 +14521,7 @@ package body Sem_Prag is ...@@ -14521,7 +14521,7 @@ package body Sem_Prag is
-- described in "Handling of Default and Per-Object -- described in "Handling of Default and Per-Object
-- Expressions" in sem.ads. -- Expressions" in sem.ads.
Preanalyze_Spec_Expression (Arg, Standard_Integer); Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
if not Is_Static_Expression (Arg) then if not Is_Static_Expression (Arg) then
Check_Restriction (Static_Priorities, Arg); Check_Restriction (Static_Priorities, Arg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment