From b25ce290ca03957618015e02f49fbcf79062c7fc Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Tue, 15 May 2012 12:11:10 +0000 Subject: sem_ch5.adb (Analyze_Iterator_Specification): Set kind of loop variable after pre-analysis of iterator name... 2012-05-15 Ed Schonberg * sem_ch5.adb (Analyze_Iterator_Specification): Set kind of loop variable after pre-analysis of iterator name, to prevent premature usage of loop variable. 2012-05-15 Ed Schonberg * sem_util.adb (Is_Variable): In Ada 2012, an explicit dereference that is a rewriting of an expression whose type has a declared Implicit_Derenference aspect is a variable. From-SVN: r187531 --- gcc/ada/ChangeLog | 12 ++++++++++++ gcc/ada/sem_ch5.adb | 13 ++++++++++++- gcc/ada/sem_util.adb | 12 +++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 605539b..e838b66 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,15 @@ +2012-05-15 Ed Schonberg + + * sem_ch5.adb (Analyze_Iterator_Specification): Set kind of + loop variable after pre-analysis of iterator name, to prevent + premature usage of loop variable. + +2012-05-15 Ed Schonberg + + * sem_util.adb (Is_Variable): In Ada 2012, an explicit + dereference that is a rewriting of an expression whose type has + a declared Implicit_Derenference aspect is a variable. + 2012-05-15 Hristian Kirtchev * exp_ch4.adb (Insert_Dereference_Action): Reimplemented. The diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb index ba94d77..1c0a5d4 100644 --- a/gcc/ada/sem_ch5.adb +++ b/gcc/ada/sem_ch5.adb @@ -1650,7 +1650,6 @@ package body Sem_Ch5 is begin Enter_Name (Def_Id); - Set_Ekind (Def_Id, E_Variable); if Present (Subt) then Analyze (Subt); @@ -1658,6 +1657,11 @@ package body Sem_Ch5 is Preanalyze_Range (Iter_Name); + -- Set the kind of the loop variable, which is not visible within + -- the iterator name. + + Set_Ekind (Def_Id, E_Variable); + -- If the domain of iteration is an expression, create a declaration for -- it, so that finalization actions are introduced outside of the loop. -- The declaration must be a renaming because the body of the loop may @@ -1679,6 +1683,13 @@ package body Sem_Ch5 is begin Typ := Etype (Iter_Name); + -- Protect against malformed iterator. + + if Typ = Any_Type then + Error_Msg_N ("invalid expression in loop iterator", Iter_Name); + return; + end if; + -- The name in the renaming declaration may be a function call. -- Indicate that it does not come from source, to suppress -- spurious warnings on renamings of parameterless functions, diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index bf245f0..16193e4 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -8674,7 +8674,17 @@ package body Sem_Util is or else Is_Variable_Prefix (Original_Node (Prefix (N))); - -- A function call is never a variable + -- in Ada 2012, the dereference may have been added for a type with + -- a declared implicit dereference aspect. + + elsif Nkind (N) = N_Explicit_Dereference + and then Present (Etype (Orig_Node)) + and then Ada_Version >= Ada_2012 + and then Has_Implicit_Dereference (Etype (Orig_Node)) + then + return True; + + -- A function call is never a variable. elsif Nkind (N) = N_Function_Call then return False; -- cgit v1.1