From 7eafe8e9e9ec08f1d8b2f4ea0da2f47a7dedbeaa Mon Sep 17 00:00:00 2001
From: Javier Miranda <miranda@adacore.com>
Date: Sun, 20 Oct 2024 12:13:03 +0000
Subject: [PATCH] ada: Constraint error not raised in ACATS test c413007

Reverse the meaning of switch -gnatd_P; that is, enable by default
the generating of a runtime check when the prefix of the call is
an access-to-subprogram type with a null value.

gcc/ada/ChangeLog:

	* sem_res.adb (Resolve_Actuals): Add by default a null-exclusion
	check on the prefix of the call when it is an access-type; it can
	be disabled using -gnatd_P.
	* debug.adb (gnatd_P): Update documentation.
---
 gcc/ada/debug.adb   | 17 +++++++++--------
 gcc/ada/sem_res.adb |  2 +-
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/debug.adb b/gcc/ada/debug.adb
index 9daa0110233b..2d0c32b0f094 100644
--- a/gcc/ada/debug.adb
+++ b/gcc/ada/debug.adb
@@ -180,7 +180,7 @@ package body Debug is
    --  d_M  Ignore Source_File_Name and Source_File_Name_Project pragmas
    --  d_N
    --  d_O
-   --  d_P  Enable runtime check for null prefix of prefixed subprogram call
+   --  d_P  Disable runtime check for null prefix of prefixed subprogram call
    --  d_Q
    --  d_R  For LLVM, dump the representation of records
    --  d_S
@@ -1040,13 +1040,14 @@ package body Debug is
    --       it is checked, and the progress of the recursive trace through
    --       elaboration calls at compile time.
 
-   --  d_P  For prefixed subprogram calls with an access-type prefix, generate
-   --       a null-excluding runtime check on the prefix, even when the called
-   --       subprogram has a first access parameter that does not exclude null
-   --       (that is the case only for class-wide parameter, as controlling
-   --       parameters are automatically null-excluding). In such a case,
-   --       P.Proc is equivalent to Proc(P.all'Access); see RM 6.4(9.1/5).
-   --       This includes a dereference, and thus a null check.
+   --  d_P  For prefixed subprogram calls with an access-type prefix, disable
+   --       the generation of a null-excluding runtime check on the prefix,
+   --       even when the called subprogram has a first access parameter that
+   --       does not exclude null (that is the case only for class-wide
+   --       parameter, as controlling parameters are automatically null-
+   --       excluding). In such a case, P.Proc is equivalent to the call
+   --       Proc(P.all'Access); see RM 6.4(9.1/5). This includes a dereference,
+   --       and thus a null check.
 
    --  d_R  In the LLVM backend, output the internal representation of
    --       each record
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index d2b019aef173..2d0e2be18497 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -4942,7 +4942,7 @@ package body Sem_Res is
                        A, Nam);
                   end if;
 
-                  if Debug_Flag_Underscore_PP
+                  if not Debug_Flag_Underscore_PP
                     and then
                       (Is_Controlling_Formal (F)
                          or else Is_Class_Wide_Type (Designated_Type (F_Typ)))
-- 
GitLab