- -- If component is pointer to a classwide type, freeze
- -- the specific type in the expression being allocated.
- -- The expression may be a subtype indication, in which
- -- case freeze the subtype mark.
-
- if Is_Class_Wide_Type (Designated_Type (Etype (Comp))) then
- if Is_Entity_Name (Expression (Alloc)) then
- Freeze_And_Append
- (Entity (Expression (Alloc)), Loc, Result);
- elsif
- Nkind (Expression (Alloc)) = N_Subtype_Indication
- then
- Freeze_And_Append
- (Entity (Subtype_Mark (Expression (Alloc))),
- Loc, Result);
- end if;
-
- else
- Freeze_And_Append
- (Designated_Type (Etype (Comp)), Loc, Result);
- end if;
- end;
-
- -- If this is a constrained subtype of an already frozen type,
- -- make the subtype frozen as well. It might otherwise be frozen
- -- in the wrong scope, and a freeze node on subtype has no effect.
-
- elsif Is_Access_Type (Etype (Comp))
- and then not Is_Frozen (Designated_Type (Etype (Comp)))
- and then Is_Itype (Designated_Type (Etype (Comp)))
- and then Is_Frozen (Base_Type (Designated_Type (Etype (Comp))))
- then
- Set_Is_Frozen (Designated_Type (Etype (Comp)));
-
- -- In addition, add an Itype_Reference to ensure that the
- -- access subtype is elaborated early enough. This cannot
- -- be done if the subtype may depend on discriminants.
-
- if Ekind (Comp) = E_Component
- and then Is_Itype (Etype (Comp))
- and then not Has_Discriminants (Rec)
- then
- IR := Make_Itype_Reference (Sloc (Comp));
- Set_Itype (IR, Designated_Type (Etype (Comp)));
-
- if No (Result) then
- Result := New_List (IR);
- else
- Append (IR, Result);
+ -- Freezing a record type freezes the type of each of its
+ -- components. However, if the type of the component is
+ -- part of this record, we do not want or need a separate
+ -- Freeze_Node. Note that Is_Itype is wrong because that's
+ -- also set in private type cases. We also can't check for
+ -- the Scope being exactly Rec because of private types and
+ -- record extensions.
+
+ if Is_Itype (Etype (Comp))
+ and then Is_Record_Type (Underlying_Type
+ (Scope (Etype (Comp))))
+ then
+ Undelay_Type (Etype (Comp));