aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch5.adb
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2022-06-24 14:25:48 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2022-07-12 12:24:12 +0000
commite124352c0ada83486926f110c8b28a0a431c98b4 (patch)
tree39b9113a69497e0d183cb28e60625ccb37ccfec8 /gcc/ada/sem_ch5.adb
parent6a64ee3903166dcb1a7803fbf49c31d0f89875a8 (diff)
downloadgcc-e124352c0ada83486926f110c8b28a0a431c98b4.zip
gcc-e124352c0ada83486926f110c8b28a0a431c98b4.tar.gz
gcc-e124352c0ada83486926f110c8b28a0a431c98b4.tar.bz2
[Ada] Refine heuristics for unreachable-code warnings
This patch refines the heuristics for when we warn about unreachable code, to avoid common false alarms. gcc/ada/ * sem_ch5.adb (Check_Unreachable_Code): Refine heuristics. * sem_util.ads, sem_util.adb (Is_Static_Constant_Name): Remove this; instead we have a new function Is_Simple_Case in Sem_Ch5.Check_Unreachable_Code.
Diffstat (limited to 'gcc/ada/sem_ch5.adb')
-rw-r--r--gcc/ada/sem_ch5.adb28
1 files changed, 26 insertions, 2 deletions
diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index b2a3661..e1b5722 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -4393,6 +4393,31 @@ package body Sem_Ch5 is
----------------------------
procedure Check_Unreachable_Code (N : Node_Id) is
+
+ function Is_Simple_Case (N : Node_Id) return Boolean;
+ -- N is the condition of an if statement. True if N is simple enough
+ -- that we should not set Unblocked_Exit_Count in the special case
+ -- below.
+
+ --------------------
+ -- Is_Simple_Case --
+ --------------------
+
+ function Is_Simple_Case (N : Node_Id) return Boolean is
+ begin
+ return
+ Is_Trivial_Boolean (N)
+ or else
+ (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)
+ or else
+ (not In_Instance
+ and then Nkind (Original_Node (N)) = N_Op_Not
+ and then Is_Simple_Case (Right_Opnd (Original_Node (N))));
+ end Is_Simple_Case;
+
Error_Node : Node_Id;
Nxt : Node_Id;
P : Node_Id;
@@ -4574,8 +4599,7 @@ package body Sem_Ch5 is
and then No (Else_Statements (P))
and then Is_OK_Static_Expression (Condition (P))
and then Is_True (Expr_Value (Condition (P)))
- and then not Is_Trivial_Boolean (Condition (P))
- and then not Is_Static_Constant_Name (Condition (P))
+ and then not Is_Simple_Case (Condition (P))
then
pragma Assert (Unblocked_Exit_Count = 2);
Unblocked_Exit_Count := 0;