diff mbox series

[COMMITTED] ada: Spurious reference warning on qualified expression

Message ID 20240506091825.1585922-1-poulhies@adacore.com
State New
Headers show
Series [COMMITTED] ada: Spurious reference warning on qualified expression | expand

Commit Message

Marc Poulhiès May 6, 2024, 9:18 a.m. UTC
From: Justin Squirek <squirek@adacore.com>

This patch fixes an error in the compiler whereby an assignment to an out
formal (whose type requires a predicate check) can lead to spurious
"value may be referenced before it has a value" warnings when the RHS is a
qualified expression.

gcc/ada/

	* sem_warn.adb (Within_Postcondition): Add case to ignore
	references within generated predicate function calls.

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

---
 gcc/ada/sem_warn.adb | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index eaf9a257ba0..0a54b3eda50 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1982,6 +1982,16 @@  package body Sem_Warn is
                            then
                               return True;
 
+                           --  Verify we are not within a generated predicate
+                           --  function call.
+
+                           elsif Nkind (Nod) = N_Function_Call
+                             and then Is_Entity_Name (Name (Nod))
+                             and then Is_Predicate_Function
+                                        (Entity (Name (Nod)))
+                           then
+                              return True;
+
                            elsif Present (Parent (Nod)) then
                               P := Parent (Nod);