[COMMITTED] ada: Add guard before querying the type for its interfaces

Message ID 20230905110833.563425-1-poulhies@adacore.com
State Unresolved
Headers
Series [COMMITTED] ada: Add guard before querying the type for its interfaces |

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: Piotr Trojanek <trojanek@adacore.com>

Fix crash on illegal code, when routine Iface_Present_In_Ancestor is
called on the predefined String type and attempts to examine the list of
interfaces.

gcc/ada/

	* sem_type.adb (Iface_Present_In_Ancestor): Only look at the list of
	interfaces for types that allow it. The guard is a high-level equivalent
	of the entity kinds listed in the preconditon of the Interfaces query.

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

---
 gcc/ada/sem_type.adb | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gcc/ada/sem_type.adb b/gcc/ada/sem_type.adb
index bbdcd5f24b8..8579130cdac 100644
--- a/gcc/ada/sem_type.adb
+++ b/gcc/ada/sem_type.adb
@@ -2578,7 +2578,9 @@  package body Sem_Type is
          end if;
 
          loop
-            if Present (Interfaces (E)) then
+            if Is_Record_Type (E)
+              and then Present (Interfaces (E))
+            then
                Elmt := First_Elmt (Interfaces (E));
                while Present (Elmt) loop
                   AI := Node (Elmt);