diff mbox series

[Ada] Avoid building malformed component constraints

Message ID 20220106171302.GA2921590@adacore.com
State New
Headers show
Series [Ada] Avoid building malformed component constraints | expand

Commit Message

Pierre-Marie de Rodat Jan. 6, 2022, 5:13 p.m. UTC
The previous fix introduced a not-yet-understood regression in compiling
CodePeer. For now, we attempt a quick workaround for the problem.

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

gcc/ada/

	* sem_util.adb (Build_Discriminant_Reference): In the unexpected
	case where we previously would fail an assertion, we instead
	revert to the old behavior.
diff mbox series

Patch

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -2107,11 +2107,7 @@  package body Sem_Util is
       --  Start of processing for Build_Discriminant_Reference
 
       begin
-         if Obj_Is_Good_Prefix then
-            return Make_Selected_Component (Loc,
-                     Prefix => Copy_And_Maybe_Dereference (Obj),
-                     Selector_Name => New_Occurrence_Of (Discrim, Loc));
-         else
+         if not Obj_Is_Good_Prefix then
             --  If the given discriminant is not a component of the given
             --  object, then try the enclosing object.
 
@@ -2128,10 +2124,15 @@  package body Sem_Util is
                         (Discrim_Name => Discrim_Name,
                          Obj          => Name (Parent (Entity (Obj))));
             else
-               pragma Assert (False);
-               raise Program_Error;
+               --  We are in some unexpected case here, so revert to the
+               --  old behavior (by falling through to it).
+               null;
             end if;
          end if;
+
+         return Make_Selected_Component (Loc,
+                  Prefix => Copy_And_Maybe_Dereference (Obj),
+                  Selector_Name => New_Occurrence_Of (Discrim, Loc));
       end Build_Discriminant_Reference;
 
       ------------------------------------