diff mbox series

[Ada] Hang on compilation of unit with type extension in body

Message ID 20211109094618.GA830910@adacore.com
State New
Headers show
Series [Ada] Hang on compilation of unit with type extension in body | expand

Commit Message

Pierre-Marie de Rodat Nov. 9, 2021, 9:46 a.m. UTC
This patch corrects an issue in the compiler whereby the expansion of
a type extension declared in the body of a package with an overriding
primitive causes an infinite loop during compilation when the type
being extended is both declared in the package spec and has a function
and a procedure primitive.

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

gcc/ada/

	* exp_util.adb (Ancestor_Primitive): Prevent return of an
	subprogram alias when the ancestor primitive of the alias is the
	same as Subp.
diff mbox series

Patch

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -10433,6 +10433,14 @@  package body Exp_Util is
          --  inherited ancestor primitive.
 
          elsif Present (Inher_Prim) then
+            --  It is possible that an internally generated alias could be
+            --  set to a subprogram which overrides the same aliased primitive,
+            --  so return Empty in this case.
+
+            if Ancestor_Primitive (Inher_Prim) = Subp then
+               return Empty;
+            end if;
+
             return Inher_Prim;
 
          --  Otherwise the current subprogram is the root of the inheritance or