aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYannick Moy <moy@adacore.com>2022-02-10 12:36:52 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2022-05-12 12:38:39 +0000
commitcc508db0d323279dc26e8471fd9f727492367e5c (patch)
tree153b5c9b6cd4972dead1d523df05cbc6f38b9097
parentce19ac123abde3d9c52d52e13a00bbbe60e08722 (diff)
downloadgcc-cc508db0d323279dc26e8471fd9f727492367e5c.zip
gcc-cc508db0d323279dc26e8471fd9f727492367e5c.tar.gz
gcc-cc508db0d323279dc26e8471fd9f727492367e5c.tar.bz2
[Ada] Do not issue a warning on a postcondition of True or False
Do not issue a warning about the postcondition of a function not mentioning its result when this postcondition is statically True or False, as this is a specification of non-termination (for value False) or a hint to SPARK prover for not inlining an expression function (for value True). In any case, the warning brings no value here. gcc/ada/ * sem_util.adb (Check_Result_And_Post_State): Exempt trivial post.
-rw-r--r--gcc/ada/sem_util.adb44
1 files changed, 24 insertions, 20 deletions
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 20253bd..0b7d351 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -4813,6 +4813,9 @@ package body Sem_Util is
-- and post-state. Prag is a [refined] postcondition or a contract-cases
-- pragma. Result_Seen is set when the pragma mentions attribute 'Result
+ function Is_Trivial_Boolean (N : Node_Id) return Boolean;
+ -- Determine whether source node N denotes "True" or "False"
+
-------------------------------------------
-- Check_Result_And_Post_State_In_Pragma --
-------------------------------------------
@@ -4836,9 +4839,6 @@ package body Sem_Util is
function Is_Function_Result (N : Node_Id) return Traverse_Result;
-- Attempt to find attribute 'Result in a subtree denoted by N
- function Is_Trivial_Boolean (N : Node_Id) return Boolean;
- -- Determine whether source node N denotes "True" or "False"
-
function Mentions_Post_State (N : Node_Id) return Boolean;
-- Determine whether a subtree denoted by N mentions any construct
-- that denotes a post-state.
@@ -5089,20 +5089,6 @@ package body Sem_Util is
end if;
end Is_Function_Result;
- ------------------------
- -- Is_Trivial_Boolean --
- ------------------------
-
- function Is_Trivial_Boolean (N : Node_Id) return Boolean is
- begin
- return
- Comes_From_Source (N)
- and then Is_Entity_Name (N)
- and then (Entity (N) = Standard_True
- or else
- Entity (N) = Standard_False);
- end Is_Trivial_Boolean;
-
-------------------------
-- Mentions_Post_State --
-------------------------
@@ -5202,6 +5188,20 @@ package body Sem_Util is
end if;
end Check_Result_And_Post_State_In_Pragma;
+ ------------------------
+ -- Is_Trivial_Boolean --
+ ------------------------
+
+ function Is_Trivial_Boolean (N : Node_Id) return Boolean is
+ begin
+ return
+ Comes_From_Source (N)
+ and then Is_Entity_Name (N)
+ and then (Entity (N) = Standard_True
+ or else
+ Entity (N) = Standard_False);
+ end Is_Trivial_Boolean;
+
-- Local variables
Items : constant Node_Id := Contract (Subp_Id);
@@ -5305,10 +5305,14 @@ package body Sem_Util is
elsif Present (Case_Prag) and then not Seen_In_Case then
Error_Msg_N ("contract cases do not mention result?.t?", Case_Prag);
- -- The function has postconditions only and they do not mention
- -- attribute 'Result.
+ -- The function has non-trivial postconditions only and they do not
+ -- mention attribute 'Result.
- elsif Present (Post_Prag) and then not Seen_In_Post then
+ elsif Present (Post_Prag)
+ and then not Seen_In_Post
+ and then not Is_Trivial_Boolean
+ (Get_Pragma_Arg (First (Pragma_Argument_Associations (Post_Prag))))
+ then
Error_Msg_N
("postcondition does not mention function result?.t?", Post_Prag);
end if;