[COMMITTED] ada: Avoid crash in Find_Optional_Prim_Op

Message ID 20230706113855.1766024-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Avoid crash in Find_Optional_Prim_Op |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Marc Poulhiès July 6, 2023, 11:38 a.m. UTC
  From: Viljar Indus <indus@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_util.adb | 5 +++++
 1 file changed, 5 insertions(+)
  

Patch

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index c74921e1772..66e1acbf65e 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -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));