[Ada] Assert failure on invalid Variable_Indexing

Message ID 20200707092736.GA41699@adacore.com
State New
Headers show
  • [Ada] Assert failure on invalid Variable_Indexing
Related show

Commit Message

Pierre-Marie de Rodat July 7, 2020, 9:27 a.m.
GNAT is getting confused and will either generate an assert failure or a
confusing error message (when assertions are disabled) in case of an
invalid Variable_Indexing.

Tested on x86_64-pc-linux-gnu, committed on trunk


	* sem_ch4.adb (Try_Container_Indexing): Add ??? comment. Protect
	against malformed tree in case of errors.


diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -286,6 +286,7 @@  package body Sem_Ch4 is
       Prefix : Node_Id;
       Exprs  : List_Id) return Boolean;
    --  AI05-0139: Generalized indexing to support iterators over containers
+   --  ??? Need to provide a more detailed spec of what this function does
    function Try_Indexed_Call
      (N          : Node_Id;
@@ -8469,6 +8470,12 @@  package body Sem_Ch4 is
       if not Is_Overloaded (Func_Name) then
          Func := Entity (Func_Name);
+         --  Can happen in case of e.g. cascaded errors
+         if No (Func) then
+            return False;
+         end if;
          Indexing :=
            Make_Function_Call (Loc,
              Name                   => New_Occurrence_Of (Func, Loc),