diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2008-05-14 07:07:24 +0000 |
---|---|---|
committer | Samuel Tardieu <sam@gcc.gnu.org> | 2008-05-14 07:07:24 +0000 |
commit | eaa2f8c7e6ae12642905df0e518d58b724bccf5f (patch) | |
tree | 1939edff40cd3e3eb25681a742a9b0853753fd55 /gcc/ada/sem_attr.adb | |
parent | 0beb3d66eabd1090b50ac68e1741756db72f595a (diff) | |
download | gcc-eaa2f8c7e6ae12642905df0e518d58b724bccf5f.zip gcc-eaa2f8c7e6ae12642905df0e518d58b724bccf5f.tar.gz gcc-eaa2f8c7e6ae12642905df0e518d58b724bccf5f.tar.bz2 |
sem_attr.adb (Analyze_Attribute, [...]): Add restrictions to the prefix of 'Old.
gcc/ada/
* sem_attr.adb (Analyze_Attribute, Attribute_Old case): Add
restrictions to the prefix of 'Old.
* sem_util.ads, sem_util.adb (In_Parameter_Specification): New.
* gnat_rm.texi ('Old): Note that 'Old cannot be applied to local
variables.
gcc/testsuite/
* gnat.dg/old_errors.ads, gnat.dg/old_errors.adb: New.
Co-Authored-By: Robert Dewar <dewar@adacore.com>
From-SVN: r135282
Diffstat (limited to 'gcc/ada/sem_attr.adb')
-rw-r--r-- | gcc/ada/sem_attr.adb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index 7550d90..6a7846e 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -3480,6 +3480,68 @@ package body Sem_Attr is Error_Attr ("attribute % cannot apply to limited objects", P); end if; + -- Check that the expression does not refer to local entities + + Check_Local : declare + Subp : Entity_Id := Current_Subprogram; + + function Process (N : Node_Id) return Traverse_Result; + -- Check that N does not contain references to local variables + -- or other local entities of Subp. + + ------------- + -- Process -- + ------------- + + function Process (N : Node_Id) return Traverse_Result is + begin + if Is_Entity_Name (N) + and then not Is_Formal (Entity (N)) + and then Enclosing_Subprogram (Entity (N)) = Subp + then + Error_Msg_Node_1 := Entity (N); + Error_Attr + ("attribute % cannot refer to local variable&", N); + end if; + + return OK; + end Process; + + procedure Check_No_Local is new Traverse_Proc; + + -- Start of processing for Check_Local + + begin + Check_No_Local (P); + + if In_Parameter_Specification (P) then + + -- We have additional restrictions on using 'Old in parameter + -- specifications. + + if Present (Enclosing_Subprogram (Current_Subprogram)) then + + -- Check that there is no reference to the enclosing + -- subprogram local variables. Otherwise, we might end + -- up being called from the enclosing subprogram and thus + -- using 'Old on a local variable which is not defined + -- at entry time. + + Subp := Enclosing_Subprogram (Current_Subprogram); + Check_No_Local (P); + + else + -- We must prevent default expression of library-level + -- subprogram from using 'Old, as the subprogram may be + -- used in elaboration code for which there is no enclosing + -- subprogram. + + Error_Attr + ("attribute % can only appear within subprogram", N); + end if; + end if; + end Check_Local; + ------------ -- Output -- ------------ |