diff options
author | Bob Duff <duff@adacore.com> | 2021-05-04 10:13:36 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2021-07-06 14:46:52 +0000 |
commit | 68c27b2a702d073e21cd41c0080c849f7a4804ca (patch) | |
tree | 6b17c1d79cd1073f8ca379801961c3af200c00de | |
parent | 885efc5e70f46c8fe38855815bb37fecc5783046 (diff) | |
download | gcc-68c27b2a702d073e21cd41c0080c849f7a4804ca.zip gcc-68c27b2a702d073e21cd41c0080c849f7a4804ca.tar.gz gcc-68c27b2a702d073e21cd41c0080c849f7a4804ca.tar.bz2 |
[Ada] Add assertions on tampering counts
gcc/ada/
* libgnat/a-conhel.adb: Assert that tampering counts remain
between 0 and 2**31-1. This makes debugging of
finalization-related bugs easier.
-rw-r--r-- | gcc/ada/libgnat/a-conhel.adb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gcc/ada/libgnat/a-conhel.adb b/gcc/ada/libgnat/a-conhel.adb index e7d82ac..316c866 100644 --- a/gcc/ada/libgnat/a-conhel.adb +++ b/gcc/ada/libgnat/a-conhel.adb @@ -27,6 +27,13 @@ package body Ada.Containers.Helpers is + Max_Count : constant := 2**31 - 1; + -- Used in assertions below, to make sure the counts don't wrap around. + -- This can help detect bugs in which Adjust and Finalize calls are + -- improperly generated. An extra Decrement could otherwise cause + -- wraparound from 0 to 2**32-1. The highest count seen so far is + -- around 25, so this should be plenty. + package body Generic_Implementation is use type SAC.Atomic_Unsigned; @@ -50,6 +57,7 @@ package body Ada.Containers.Helpers is begin if T_Check then SAC.Increment (T_Counts.Busy); + pragma Assert (T_Counts.Busy <= Max_Count); end if; end Busy; @@ -112,7 +120,9 @@ package body Ada.Containers.Helpers is begin if T_Check then SAC.Increment (T_Counts.Lock); + pragma Assert (T_Counts.Lock <= Max_Count); SAC.Increment (T_Counts.Busy); + pragma Assert (T_Counts.Busy <= Max_Count); end if; end Lock; @@ -158,6 +168,7 @@ package body Ada.Containers.Helpers is begin if T_Check then SAC.Decrement (T_Counts.Busy); + pragma Assert (T_Counts.Busy <= Max_Count); end if; end Unbusy; @@ -169,7 +180,9 @@ package body Ada.Containers.Helpers is begin if T_Check then SAC.Decrement (T_Counts.Lock); + pragma Assert (T_Counts.Lock <= Max_Count); SAC.Decrement (T_Counts.Busy); + pragma Assert (T_Counts.Busy <= Max_Count); end if; end Unlock; |