]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix crash when checking ghost levels of call arguments
authorViljar Indus <indus@adacore.com>
Thu, 27 Nov 2025 09:07:19 +0000 (11:07 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 9 Jan 2026 10:57:13 +0000 (11:57 +0100)
We should avoid the check if the called entity cannot have formals

gcc/ada/ChangeLog:

* einfo-utils.adb (Can_Have_Formals): New function for checking
if the entity can support formals.
* einfo-utils.ads (Can_Have_Formals): Likewise.
* ghost.adb (Check_Procedure_Call_Argument_Levels): Avoid checking
the type of the formal if the called entity cannot hold formals.

gcc/ada/einfo-utils.adb
gcc/ada/einfo-utils.ads
gcc/ada/ghost.adb

index 22f50221ddcd9b92e9a39c1c0efc8ea9487a9e41..87fb2f56af751c41ccf7deed84c84cbfd99d4f39 100644 (file)
@@ -704,6 +704,12 @@ package body Einfo.Utils is
       end return;
    end Base_Type_If_Set;
 
+   function Can_Have_Formals (Id : Entity_Id) return Boolean
+   is (Is_Generic_Subprogram (Id)
+       or else Is_Overloadable (Id)
+       or else Ekind (Id)
+               in E_Entry_Family | E_Subprogram_Body | E_Subprogram_Type);
+
    ----------------------
    -- Declaration_Node --
    ----------------------
@@ -856,12 +862,7 @@ package body Einfo.Utils is
       Formal : Entity_Id;
 
    begin
-      pragma Assert
-        (Is_Generic_Subprogram (Id)
-           or else Is_Overloadable (Id)
-           or else Ekind (Id) in E_Entry_Family
-                               | E_Subprogram_Body
-                               | E_Subprogram_Type);
+      pragma Assert (Can_Have_Formals (Id));
 
       if Ekind (Id) = E_Enumeration_Literal then
          return Empty;
@@ -897,12 +898,7 @@ package body Einfo.Utils is
       Formal : Entity_Id;
 
    begin
-      pragma Assert
-        (Is_Generic_Subprogram (Id)
-           or else Is_Overloadable (Id)
-           or else Ekind (Id) in E_Entry_Family
-                               | E_Subprogram_Body
-                               | E_Subprogram_Type);
+      pragma Assert (Can_Have_Formals (Id));
 
       if Ekind (Id) = E_Enumeration_Literal then
          return Empty;
@@ -1823,11 +1819,7 @@ package body Einfo.Utils is
       Formal : Entity_Id;
 
    begin
-      pragma Assert
-        (Is_Overloadable (Id)
-          or else Ekind (Id) in E_Entry_Family
-                              | E_Subprogram_Body
-                              | E_Subprogram_Type);
+      pragma Assert (Can_Have_Formals (Id));
 
       if Ekind (Id) = E_Enumeration_Literal then
          return Empty;
index 212caf0ddf225fed0180dba37dce9dc9c1f398a0..858652739a2fae27d05c213dde1ca6d6b3ab0406 100644 (file)
@@ -551,6 +551,9 @@ package Einfo.Utils is
    --  Call [Set_]Is_Volatile_Type/Is_Volatile_Object as appropriate for the
    --  Ekind of Id.
 
+   function Can_Have_Formals (Id : Entity_Id) return Boolean;
+   --  A utility function to see whether the entity can have formals.
+
    function Convention
      (N : Entity_Id) return Convention_Id renames Basic_Convention;
    procedure Set_Convention (E : Entity_Id; Val : Convention_Id);
index 58d320006eb1af0f137549d1a6de93ca7ef64e7a..5231ef90e08415dde0832e6a638ed10f034ec402 100644 (file)
@@ -2334,13 +2334,14 @@ package body Ghost is
       --  we are not dealing with an expanded construct.
 
       if Present (Id)
+        and then Can_Have_Formals (Id)
         and then Comes_From_Source (N)
         and then Ghost_Config.Ghost_Mode /= None
       then
          Orig_Actual := First_Actual (N);
          Formal := First_Formal (Id);
 
-         while Present (Orig_Actual) loop
+         while Present (Orig_Actual) and then Present (Formal) loop
             --  Similarly to Mark_And_Set_Ghost_Procedure_Call we need to
             --  analyze the call argument first to get its level for this
             --  analysis.