[COMMITTED] ada: Improve defense against illegal code in check for infinite loops

Message ID 20230728073032.1852060-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Improve defense against illegal code in check for infinite loops |

Checks

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

Commit Message

Marc Poulhiès July 28, 2023, 7:30 a.m. UTC
  From: Piotr Trojanek <trojanek@adacore.com>

Fix crash occurring when attribute System'To_Address is used without
a WITH clause for package System.

gcc/ada/

	* sem_warn.adb (Check_Infinite_Loop_Warning): Don't look at the type of
	actual parameter when it has no type at all, e.g. because the entire
	subprogram call is illegal.

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

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

Patch

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 5dd7c17d4e2..7ecb4d9c4a6 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -591,7 +591,9 @@  package body Sem_Warn is
             begin
                Actual := First_Actual (N);
                while Present (Actual) loop
-                  if Is_Access_Subprogram_Type (Etype (Actual)) then
+                  if No (Etype (Actual))
+                    or else Is_Access_Subprogram_Type (Etype (Actual))
+                  then
                      return Abandon;
                   else
                      Next_Actual (Actual);