]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: vast: protect against a predicate failure
authorMarc Poulhiès <poulhies@adacore.com>
Tue, 3 Mar 2026 10:45:20 +0000 (11:45 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 28 May 2026 08:52:50 +0000 (10:52 +0200)
In case where the node is not a Pragma as expected, don't try to check
its field as it can raise a predicate error.

gcc/ada/ChangeLog:

* vast.adb (Do_Node_Pass_2): Only check aspect/pragma consistency for pragma nodes.

gcc/ada/vast.adb

index 4a26ddb5b8464c686d329d917cee45c4bdae3c46..d511532a3fc063c182841b5c1ff10c6acac9b945 100644 (file)
@@ -636,10 +636,16 @@ package body VAST is
          if Present (Aspect_Rep_Item (N)) then
             Assert (Nkind (Aspect_Rep_Item (N)) = N_Pragma,
                     Check_Corresponding_Aspect);
-            Assert (From_Aspect_Specification (Aspect_Rep_Item (N)),
-                    Check_Corresponding_Aspect);
-            Assert (Corresponding_Aspect (Aspect_Rep_Item (N)) = N,
-                    Check_Corresponding_Aspect);
+
+            --  If the above check fails, the test below may raise predicate
+            --  failures, no need to check for pragma/aspect consistency for
+            --  other nodes.
+            if Nkind (Aspect_Rep_Item (N)) = N_Pragma then
+               Assert (From_Aspect_Specification (Aspect_Rep_Item (N)),
+                       Check_Corresponding_Aspect);
+               Assert (Corresponding_Aspect (Aspect_Rep_Item (N)) = N,
+                       Check_Corresponding_Aspect);
+            end if;
          end if;
       end if;