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 Is_Global_Entity.
Tested on x86-64/Linux, applied on the mainline and 15 branch.
2026-02-08 Eric Botcazou <[email protected]>
Liam Powell <[email protected]>
PR ada/124025
* exp_ch9.adb (Expand_Entry_Barrier.Is_Global_Entity): Use
Scope_Within_Or_Same to test whether the object is local.
2026-02-08 Eric Botcazou <[email protected]>
Liam Powell <[email protected]>
* gnat.dg/protected_type1.adb: New test.
--
Eric Botcazoudiff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index a2769df383d..2f5446e79f1 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -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
-- { 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;