[COMMITTED,18/51] ada: Fix crash in Has_Assertion_Level_Argument

Message ID 20260602084541.3829876-18-poulhies@adacore.com
State Committed
Commit 65bac7957e117f7300dcd0ad61345c675acceb45
Headers
Series [COMMITTED,01/51] ada: Rename Private_Component function |

Commit Message

Marc Poulhiès June 2, 2026, 8:45 a.m. UTC
  From: Viljar Indus <indus@adacore.com>

This method would crash if the association was not a
N_Component_Association. As it could be something else like an
N_Iterated_Component_Association that does not have the choices
attribute.

gcc/ada/ChangeLog:

	* sem_util.adb (Has_Assertion_Level_Argument): Check for
	the correct type of association.

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

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

Patch

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 5698b2f0fef..43850d6cfc2 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -11510,6 +11510,11 @@  package body Sem_Util is
          end if;
 
          Assoc := First (Assocs);
+
+         if Nkind (Assoc) /= N_Component_Association then
+            return False;
+         end if;
+
          Choice := First (Choices (Assoc));
 
          if Nkind (Choice) = N_Identifier then