]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Avoid crash in Find_Optional_Prim_Op
authorViljar Indus <indus@adacore.com>
Wed, 14 Jun 2023 20:19:49 +0000 (23:19 +0300)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 6 Jul 2023 11:36:09 +0000 (13:36 +0200)
Find_Optional_Prim_Op can crash when the Underlying_Type is Empty.
This can happen when you are dealing with a structure type with a
private part that does not have its Full_View set yet.

gcc/ada/

* exp_util.adb (Find_Optional_Prim_Op): Stop deriving primitive
operation if there is no underlying type to derive it from.

gcc/ada/exp_util.adb

index c74921e1772a591883b82abd6220ffb65a4cb827..66e1acbf65eec32afecae9c5111987781472fa64 100644 (file)
@@ -6291,6 +6291,11 @@ package body Exp_Util is
 
       Typ := Underlying_Type (Typ);
 
+      --  We cannot find the operation if there is no full view available.
+      if Typ = Empty then
+         return Empty;
+      end if;
+
       --  Loop through primitive operations
 
       Prim := First_Elmt (Primitive_Operations (Typ));