This occurs when the type of the protected object is a constrained subtype of
an unconstrained protected type, and comes from an obsolete kludge.
Tested on x86-64/Linux, applied on the mainline and 16 branch.
2026-10-07 Eric Botcazou <[email protected]>
PR ada/127756
* exp_util.adb (Find_Protection_Type): Remove early return.
2026-10-07 Eric Botcazou <[email protected]>
* gnat.dg/protected_subtype2.adb: New test.
--
Eric Botcazoudiff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index d587fb16c8f..24828e4a250 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -7220,15 +7220,6 @@ package body Exp_Util is
Typ := Corresponding_Record_Type (Typ);
end if;
- -- Since restriction violations are not considered serious errors, the
- -- expander remains active, but may leave the corresponding record type
- -- malformed. In such cases, component _object is not available so do
- -- not look for it.
-
- if not Analyzed (Typ) then
- return Empty;
- end if;
-
Comp := First_Component (Typ);
while Present (Comp) loop
if Chars (Comp) = Name_uObject then
-- { dg-do compile }
with Ada.Unchecked_Deallocation;
procedure Protected_Subtype2 is
protected type State (Capacity : Positive) with Lock_Free => False is
procedure Touch;
private
Value : Natural := 0;
end State;
protected body State is
procedure Touch is
begin
Value := Value + 1;
end Touch;
end State;
subtype Constrained_State is State (4);
type State_Access is access Constrained_State;
procedure Free is
new Ada.Unchecked_Deallocation (Constrained_State, State_Access);
begin
for I in 1 .. 100 loop
declare
P : State_Access := new Constrained_State;
begin
P.Touch;
Free (P);
end;
end loop;
end;
-- { dg-final { scan-assembler "finalize_protection" } }