[COMMITTED] ada: Prevent search of calls in preconditions from going too far

Message ID 20230525080552.1956593-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Prevent search of calls in preconditions from going too far |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

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

When determining whether a call to protected function appears within
a pragma expression we can safely stop at the subprogram body.

Cleanup related to recently added support for a new SPARK aspects,
whose implementation was based on Contract_Cases.

gcc/ada/

	* sem_util.adb (Check_Internal_Protected_Use): Add standard protection
	against search going too far.

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

---
 gcc/ada/sem_util.adb | 5 +++++
 1 file changed, 5 insertions(+)
  

Patch

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 2e2fb911c38..bfe1b9fc74d 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -3501,6 +3501,11 @@  package body Sem_Util is
                     ("internal call cannot appear in default for formal of "
                      & "protected operation", N);
                   return;
+
+               --  Prevent the search from going too far
+
+               elsif Is_Body_Or_Package_Declaration (P) then
+                  exit;
                end if;
 
                P := Parent (P);