]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Remove spurious error on attribute Count with expansion disabled
authorPiotr Trojanek <trojanek@adacore.com>
Mon, 16 Feb 2026 14:23:41 +0000 (15:23 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 28 May 2026 08:52:44 +0000 (10:52 +0200)
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.

gcc/ada/exp_ch9.adb

index 6e1e0fedf34c9ed1f0b31ec1ad6b100f4760d593..08ff42ee32b0ca15283b80214c9d20934440c984 100644 (file)
@@ -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