2012-05-15 Ed Schonberg <schonberg@adacore.com>
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 15 May 2012 12:11:10 +0000 (12:11 +0000)
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 15 May 2012 12:11:10 +0000 (12:11 +0000)
* 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  <schonberg@adacore.com>

* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@187531 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/sem_ch5.adb
gcc/ada/sem_util.adb

index 605539b..e838b66 100644 (file)
@@ -1,3 +1,15 @@
+2012-05-15  Ed Schonberg  <schonberg@adacore.com>
+
+       * 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  <schonberg@adacore.com>
+
+       * 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  <kirtchev@adacore.com>
 
        * exp_ch4.adb (Insert_Dereference_Action): Reimplemented. The
index ba94d77..1c0a5d4 100644 (file)
@@ -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,
index bf245f0..16193e4 100644 (file)
@@ -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;