aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2021-11-30 16:00:40 -0500
committerPierre-Marie de Rodat <derodat@adacore.com>2022-01-05 11:32:35 +0000
commita6505936a35e7a5c66e36f7c4e2032c5c7f64838 (patch)
tree161f8a7cce508871ac49e9bcbec33d9ece175b79 /gcc
parent54403a8130c126cc3e901341dac64afbc7273347 (diff)
downloadgcc-a6505936a35e7a5c66e36f7c4e2032c5c7f64838.zip
gcc-a6505936a35e7a5c66e36f7c4e2032c5c7f64838.tar.gz
gcc-a6505936a35e7a5c66e36f7c4e2032c5c7f64838.tar.bz2
[Ada] Prevent Get_Current_Value_Condition from returning the same node
gcc/ada/ * exp_util.ads (Get_Current_Value_Condition): Belt: Add a postcondition that Val /= Var. * sem_util.adb (Known_Null): Suspenders: Raise Program_Error if Get_Current_Value_Condition returned the same value. This will be enabled even without assertions, because infinite recursion is a nuisance -- better to crash if this bug ever occurs.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/exp_util.ads2
-rw-r--r--gcc/ada/sem_util.adb7
2 files changed, 8 insertions, 1 deletions
diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads
index 2b61132..773fa01 100644
--- a/gcc/ada/exp_util.ads
+++ b/gcc/ada/exp_util.ads
@@ -703,7 +703,7 @@ package Exp_Util is
procedure Get_Current_Value_Condition
(Var : Node_Id;
Op : out Node_Kind;
- Val : out Node_Id);
+ Val : out Node_Id) with Post => Val /= Var;
-- This routine processes the Current_Value field of the variable Var. If
-- the Current_Value field is null or if it represents a known value, then
-- on return Cond is set to N_Empty, and Val is set to Empty.
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 49a58e3c..7064dfa 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -22062,6 +22062,13 @@ package body Sem_Util is
Get_Current_Value_Condition (N, Op, Val);
+ -- If Get_Current_Value_Condition were to return Val = N, then the
+ -- recursion below could be infinite.
+
+ if Val = N then
+ raise Program_Error;
+ end if;
+
if Known_Null (Val) then
if Op = N_Op_Eq then
return True;