]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Storage_Error raised analyzing type with call in its range constraint
authorJustin Squirek <squirek@adacore.com>
Tue, 6 Sep 2022 14:35:53 +0000 (14:35 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 12 Sep 2022 08:16:53 +0000 (10:16 +0200)
This patch corrects a problem in the compiler whereby the determination of
scope levels during the generation of accessibility checks for function calls
within range constraints leads to a compiler crash due to the type not being
fully analyzed at the point in which its scope depth must be obtained.

gcc/ada/

* sem_util.adb
(Innermost_Master_Scope_Depth): Detect and handle case where scope
depth is not set on an enclosing scope.

gcc/ada/sem_util.adb

index 8c64ac31dd303ba5d6431206394ebc31899c02be..b0babeb9d6f19679a6c7d8cfbc6452b054e04e73 100644 (file)
@@ -316,8 +316,20 @@ package body Sem_Util is
                --  Ignore transient scopes made during expansion
 
                if Comes_From_Source (Node_Par) then
-                  return
-                    Scope_Depth (Encl_Scop) + Master_Lvl_Modifier;
+                  --  Note that in some rare cases the scope depth may not be
+                  --  set, for example, when we are in the middle of analyzing
+                  --  a type and the enclosing scope is said type. So, instead,
+                  --  continue to move up the parent chain since the scope
+                  --  depth of the type's parent is the same as that of the
+                  --  type.
+
+                  if not Scope_Depth_Set (Encl_Scop) then
+                     pragma Assert (Nkind (Parent (Encl_Scop))
+                                     = N_Full_Type_Declaration);
+                  else
+                     return
+                       Scope_Depth (Encl_Scop) + Master_Lvl_Modifier;
+                  end if;
                end if;
 
             --  For a return statement within a function, return