aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_util.adb
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2022-06-23 12:29:22 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2022-07-12 12:24:12 +0000
commit6a64ee3903166dcb1a7803fbf49c31d0f89875a8 (patch)
tree171d28ecdb42c209b974001827b72854f9166a62 /gcc/ada/sem_util.adb
parent6882d60a10060a7f3c73e73eb7f10239e1a4f905 (diff)
downloadgcc-6a64ee3903166dcb1a7803fbf49c31d0f89875a8.zip
gcc-6a64ee3903166dcb1a7803fbf49c31d0f89875a8.tar.gz
gcc-6a64ee3903166dcb1a7803fbf49c31d0f89875a8.tar.bz2
[Ada] Remove out-of-range warning in unreachable code
This patch removes a warning in examples like this: if cond then return; -- or other jump end if; X := ...; -- where the value is out of range where cond is known at compile time. It could, for example, be a generic formal parameter that is known to be True in some instances. As a side effect, this patch adds new warnings about unreachable code. gcc/ada/ * gnatls.adb (Output_License_Information): Remove pragma No_Return; call sites deal with Exit_Program. * libgnat/g-socthi.adb (C_Connect): Suppress warning about unreachable code. * sem_ch5.adb (Check_Unreachable_Code): Special-case if statements with static conditions. If we remove unreachable code (including the return statement) from a function, add "raise Program_Error", so we won't warn about missing returns. Remove Original_Node in test for N_Raise_Statement; it's not needed. Remove test for CodePeer_Mode; if Operating_Mode = Generate_Code, then CodePeer_Mode can't be True. Misc cleanup. Do not reuse Nxt variable for unrelated purpose (the usage in the Kill_Dead_Code loop is entirely local to the loop). * sem_ch6.adb: Add check for Is_Transfer. Misc cleanup. * sem_prag.adb: Minor. * sem_res.adb: Minor. * sem_util.adb: Minor cleanup. (Is_Trivial_Boolean): Move to nonnested place, so it can be called from elsewhere. (Is_Static_Constant_Boolean): New function. * sem_util.ads (Is_Trivial_Boolean): Export. (Is_Static_Constant_Boolean): New function.
Diffstat (limited to 'gcc/ada/sem_util.adb')
-rw-r--r--gcc/ada/sem_util.adb56
1 files changed, 29 insertions, 27 deletions
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 9cff0f7..cfbf010 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -4868,9 +4868,6 @@ 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 --
-------------------------------------------
@@ -5243,20 +5240,6 @@ 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);
@@ -21501,19 +21484,15 @@ package body Sem_Util is
Kind : constant Node_Kind := Nkind (N);
begin
- if Kind = N_Simple_Return_Statement
- or else
- Kind = N_Extended_Return_Statement
- or else
- Kind = N_Goto_Statement
- or else
- Kind = N_Raise_Statement
- or else
- Kind = N_Requeue_Statement
+ if Kind in N_Simple_Return_Statement
+ | N_Extended_Return_Statement
+ | N_Goto_Statement
+ | N_Raise_Statement
+ | N_Requeue_Statement
then
return True;
- elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
+ elsif Kind in N_Exit_Statement | N_Raise_xxx_Error
and then No (Condition (N))
then
return True;
@@ -21542,6 +21521,29 @@ package body Sem_Util is
return No (U) or else U = Uint_1;
end Is_True;
+ ------------------------
+ -- Is_Trivial_Boolean --
+ ------------------------
+
+ function Is_Trivial_Boolean (N : Node_Id) return Boolean is
+ begin
+ return Comes_From_Source (N)
+ and then Nkind (N) in N_Identifier | N_Expanded_Name
+ and then Entity (N) in Standard_True | Standard_False;
+ end Is_Trivial_Boolean;
+
+ -----------------------------
+ -- Is_Static_Constant_Name --
+ -----------------------------
+
+ function Is_Static_Constant_Name (N : Node_Id) return Boolean is
+ begin
+ return Comes_From_Source (N)
+ and then Is_Static_Expression (N)
+ and then Nkind (N) in N_Identifier | N_Expanded_Name
+ and then Ekind (Entity (N)) = E_Constant;
+ end Is_Static_Constant_Name;
+
--------------------------------------
-- Is_Unchecked_Conversion_Instance --
--------------------------------------