[COMMITTED] ada: Fix crash on semi-recursive call in access-to-subprogram contract

Message ID 20230529082948.2411007-1-poulhies@adacore.com
State Committed
Commit 9f29fc75351870da24c1a94986be031989a88509
Headers
Series [COMMITTED] ada: Fix crash on semi-recursive call in access-to-subprogram contract |

Commit Message

Marc Poulhiès May 29, 2023, 8:29 a.m. UTC
  From: Piotr Trojanek <trojanek@adacore.com>

Calls to access-to-subprogram from its own pre/post aspects are rejected
as illegal, e.g.:

   type F is access function (X : Natural) return Boolean with
     Pre => F.all (X);

but they caused an assertion failure in detection of recursive calls.

Now they are properly recognized as recursive, but the error is
suppressed, because it has been already posted at the call node.

gcc/ada/

	* sem_res.adb (Invoked_With_Different_Arguments): Use Get_Called_Entity,
	which properly deals with calls via an access-to-subprogram; fix
	inconsistent use of a Call object declared in enclosing subprogram.

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

---
 gcc/ada/sem_res.adb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 1d4b9acb8ea..8a5f87b80ed 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -947,7 +947,7 @@  package body Sem_Res is
       --------------------------------------
 
       function Invoked_With_Different_Arguments (N : Node_Id) return Boolean is
-         Subp : constant Entity_Id := Entity (Name (N));
+         Subp : constant Entity_Id := Get_Called_Entity (N);
 
          Actual : Node_Id;
          Formal : Entity_Id;
@@ -956,7 +956,7 @@  package body Sem_Res is
          --  Determine whether the formals of the invoked subprogram are not
          --  used as actuals in the call.
 
-         Actual := First_Actual (Call);
+         Actual := First_Actual (N);
          Formal := First_Formal (Subp);
          while Present (Actual) and then Present (Formal) loop