]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Ada: Fix bogus "potentially unsynchronized barrier" warning
authorEric Botcazou <ebotcazou@adacore.com>
Sun, 8 Feb 2026 23:55:45 +0000 (00:55 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Sun, 8 Feb 2026 23:58:58 +0000 (00:58 +0100)
This is a regression present on the mainline and 15 branch: the compiler
gives a bogus "potentially unsynchronized barrier" when the condition of
an entry barrier requires the creation of a controlled temporary, because
it comes with a transient scope that fools the test on scopes done in the
Is_Global_Entity procedure.

gcc/ada/
PR ada/124025
* exp_ch9.adb (Expand_Entry_Barrier.Is_Global_Entity): Use
Scope_Within_Or_Same to test whether the object is local.

gcc/testsuite/
* gnat.dg/protected_type1.adb: New test.

Co-authored-by: Liam Powell <liam@liampwll.com>
gcc/ada/exp_ch9.adb
gcc/testsuite/gnat.dg/protected_type1.adb [new file with mode: 0644]

index a2769df383d57075cf8ae35baeb442a8a607e38d..2f5446e79f1547cbee5ffbe581817c10aec450eb 100644 (file)
@@ -5596,7 +5596,7 @@ package body Exp_Ch9 is
                --  during expansion, it is ok. If expansion is not performed,
                --  then Func is Empty so this test cannot succeed.
 
-               if Scope (E) = Func_Id then
+               if Scope_Within_Or_Same (S, Func_Id) then
                   null;
 
                --  A protected call from a barrier to another object is ok
diff --git a/gcc/testsuite/gnat.dg/protected_type1.adb b/gcc/testsuite/gnat.dg/protected_type1.adb
new file mode 100644 (file)
index 0000000..44ae674
--- /dev/null
@@ -0,0 +1,25 @@
+--  { dg-do compile }
+
+with Ada.Finalization;
+
+procedure Protected_Type1 is
+
+  type T is new Ada.Finalization.Controlled with null record;
+
+  protected type Queue is
+    entry Get_Next_Line (Line : out String);
+  private
+    A : T;
+  end Queue;
+
+  protected body Queue is
+    entry Get_Next_Line (Line : out String)
+      when A /= (Ada.Finalization.Controlled with null record) is
+    begin
+      null;
+    end Get_Next_Line;
+  end Queue;
+
+begin
+  null;
+end;