From: Viljar Indus <[email protected]>
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.
Tested on x86_64-pc-linux-gnu (before the recent bootstrap breakage), committed
on master.
---
gcc/ada/einfo-utils.adb | 26 +++++++++-----------------
gcc/ada/einfo-utils.ads | 3 +++
gcc/ada/ghost.adb | 3 ++-
3 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb
index 22f50221ddc..87fb2f56af7 100644
--- a/gcc/ada/einfo-utils.adb
+++ b/gcc/ada/einfo-utils.adb
@@ -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;
diff --git a/gcc/ada/einfo-utils.ads b/gcc/ada/einfo-utils.ads
index 212caf0ddf2..858652739a2 100644
--- a/gcc/ada/einfo-utils.ads
+++ b/gcc/ada/einfo-utils.ads
@@ -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);
diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb
index 58d320006eb..5231ef90e08 100644
--- a/gcc/ada/ghost.adb
+++ b/gcc/ada/ghost.adb
@@ -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.
--
2.51.0