From: Piotr Trojanek <[email protected]>

When expansion is disabled, e.g. because of GNAT switch -gnatc or because GNAT
is operating in the GNATprove mode, then attribute Count is not expanded and
can legitimately appear in a barrier of a protected entry, even if restriction
Pure_Barriers is enabled.

gcc/ada/ChangeLog:

        * exp_ch9.adb (Is_Pure_Barrier): Handle unexpanded attribute Count.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch9.adb | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index 6e1e0fedf34..08ff42ee32b 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -5746,6 +5746,30 @@ package body Exp_Ch9 is
                      null;
                end case;
 
+            when N_Attribute_Reference =>
+
+               --  Attribute Count has been already expanded to function call,
+               --  or it is illegal, or expansion is disabled and attribute
+               --  is legal, i.e. it is prefixed by a name of entry or by a
+               --  indexed entry family of the current protected object.
+
+               if Attribute_Name (N) = Name_Count then
+                  pragma Assert
+                    (if Serious_Errors_Detected = 0
+                     then not Expander_Active
+                     and then
+                       ((Is_Entity_Name (Prefix (N))
+                         and then Is_Entry (Entity (Prefix (N)))
+                         and then Scope (Entity (Prefix (N))) = Prot)
+                        or else
+                        (Nkind (Prefix (N)) = N_Indexed_Component
+                         and then Is_Entity_Name (Prefix (Prefix (N)))
+                         and then Is_Entry (Entity (Prefix (Prefix (N))))
+                         and then Scope (Entity (Prefix (Prefix (N)))) = Prot))
+                       );
+                  return Skip;
+               end if;
+
             when N_Function_Call =>
 
                --  Function call checks are carried out as part of the analysis
-- 
2.53.0

Reply via email to