[COMMITTED] ada: Fix crash on selected component lookup in generic instance

Message ID 20230905110826.563238-1-poulhies@adacore.com
State Unresolved
Headers
Series [COMMITTED] ada: Fix crash on selected component lookup in generic instance |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Marc Poulhiès Sept. 5, 2023, 11:08 a.m. UTC
  From: Bob Duff <duff@adacore.com>

This patch fixes a compiler crash on selected component lookup in an instance
of a generic unit when the relevant type is an itype.

gcc/ada/

	* sem_ch4.adb (Find_Component_In_Instance): Check that
	Declaration_Node (Par) is not Empty, as it is for itypes.

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

---
 gcc/ada/sem_ch4.adb | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
  

Patch

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index 8543f0d578b..50ba6c9c847 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -5212,10 +5212,14 @@  package body Sem_Ch4 is
             end if;
          end loop;
 
-         if Present (Par) and then Is_Generic_Actual_Type (Par) then
-
-            --  Now look for component in ancestor types
+         --  If Par is a generic actual, look for component in ancestor types.
+         --  Skip this if we have no Declaration_Node, as is the case for
+         --  itypes.
 
+         if Present (Par)
+           and then Is_Generic_Actual_Type (Par)
+           and then Present (Declaration_Node (Par))
+         then
             Par := Generic_Parent_Type (Declaration_Node (Par));
             loop
                Find_Component_In_Instance (Par);