* [COMMITTED] ada: Spurious reference warning on qualified expression
@ 2024-05-06 9:18 Marc Poulhiès
0 siblings, 0 replies; 4+ messages in thread
From: Marc Poulhiès @ 2024-05-06 9:18 UTC (permalink / raw)
To: gcc-patches; +Cc: Justin Squirek
From: Justin Squirek <squirek@adacore.com>
Incremental improvement/clean up.
gcc/ada/
* sem_warn.adb (Within_Postcondition): Renamed to
Within_Contract_Or_Predicate.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_warn.adb | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 0a54b3eda50..8317b449021 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1958,16 +1958,16 @@ package body Sem_Warn is
SR : Entity_Id;
SE : constant Entity_Id := Scope (E);
- function Within_Postcondition return Boolean;
- -- Returns True if N is within a Postcondition, a
- -- Refined_Post, an Ensures component in a Test_Case,
- -- or a Contract_Cases.
+ function Within_Contract_Or_Predicate return Boolean;
+ -- Returns True if N is within a contract or predicate,
+ -- an Ensures component in a Test_Case, or a
+ -- Contract_Cases.
- --------------------------
- -- Within_Postcondition --
- --------------------------
+ ----------------------------------
+ -- Within_Contract_Or_Predicate --
+ ----------------------------------
- function Within_Postcondition return Boolean is
+ function Within_Contract_Or_Predicate return Boolean is
Nod, P : Node_Id;
begin
@@ -2012,7 +2012,7 @@ package body Sem_Warn is
end loop;
return False;
- end Within_Postcondition;
+ end Within_Contract_Or_Predicate;
-- Start of processing for Potential_Unset_Reference
@@ -2136,7 +2136,7 @@ package body Sem_Warn is
-- postcondition, since the expression occurs in a
-- place unrelated to the actual test.
- if not Within_Postcondition then
+ if not Within_Contract_Or_Predicate then
-- Here we definitely have a case for giving a warning
-- for a reference to an unset value. But we don't
--
2.43.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [COMMITTED] ada: Spurious reference warning on qualified expression
@ 2024-05-06 9:18 Marc Poulhiès
0 siblings, 0 replies; 4+ messages in thread
From: Marc Poulhiès @ 2024-05-06 9:18 UTC (permalink / raw)
To: gcc-patches; +Cc: Justin Squirek
From: Justin Squirek <squirek@adacore.com>
Incremental improvement/clean up.
gcc/ada/
* sem_warn.adb (Within_Postcondition): Add coverage for
Preconditions
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_warn.adb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 54d8920a943..57bdee65356 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1978,7 +1978,8 @@ package body Sem_Warn is
if Nkind (Nod) = N_Pragma
and then
Pragma_Name_Unmapped (Nod)
- in Name_Postcondition
+ in Name_Precondition
+ | Name_Postcondition
| Name_Refined_Post
| Name_Contract_Cases
then
--
2.43.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [COMMITTED] ada: Spurious reference warning on qualified expression
@ 2024-05-06 9:18 Marc Poulhiès
0 siblings, 0 replies; 4+ messages in thread
From: Marc Poulhiès @ 2024-05-06 9:18 UTC (permalink / raw)
To: gcc-patches; +Cc: Justin Squirek
From: Justin Squirek <squirek@adacore.com>
Incremental improvement/clean up.
gcc/ada/
* sem_warn.adb (Within_Postcondition): Add/modify comments to
document various cases.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_warn.adb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 8317b449021..54d8920a943 100644
--- a/gcc/ada/sem_warn.adb
+++ b/gcc/ada/sem_warn.adb
@@ -1973,6 +1973,8 @@ package body Sem_Warn is
begin
Nod := Parent (N);
while Present (Nod) loop
+ -- General contract / predicate related pragma
+
if Nkind (Nod) = N_Pragma
and then
Pragma_Name_Unmapped (Nod)
@@ -1992,6 +1994,8 @@ package body Sem_Warn is
then
return True;
+ -- Deal with special 'Ensures' Test_Case component
+
elsif Present (Parent (Nod)) then
P := Parent (Nod);
--
2.43.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [COMMITTED] ada: Spurious reference warning on qualified expression
@ 2024-05-06 9:18 Marc Poulhiès
0 siblings, 0 replies; 4+ messages in thread
From: Marc Poulhiès @ 2024-05-06 9:18 UTC (permalink / raw)
To: gcc-patches; +Cc: Justin Squirek
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 --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);
--
2.43.2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-06 9:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-06 9:18 [COMMITTED] ada: Spurious reference warning on qualified expression Marc Poulhiès
-- strict thread matches above, loose matches on Subject: below --
2024-05-06 9:18 Marc Poulhiès
2024-05-06 9:18 Marc Poulhiès
2024-05-06 9:18 Marc Poulhiès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).