===================================================================
@@ -7463,7 +7463,7 @@ package body Exp_Ch4 is
null;
-- Don't do this optimization for the prefix of an attribute or
- -- the operand of an object renaming declaration since these are
+ -- the name of an object renaming declaration since these are
-- contexts where we do not want the value anyway.
elsif (Nkind (Par) = N_Attribute_Reference
@@ -7472,6 +7472,18 @@ package body Exp_Ch4 is
then
null;
+ -- If this is a discriminant of a component of a mutable record,
+ -- or a renaming of such, no optimization is possible, and value
+ -- must be retrieved anew. Note that in the previous case we may
+ -- be dealing with a renaming declaration, while here we may have
+ -- a use of a renaming.
+
+ elsif Nkind (P) = N_Selected_Component
+ and then Is_Record_Type (Etype (Prefix (P)))
+ and then not Is_Constrained (Etype (Prefix (P)))
+ then
+ null;
+
-- Don't do this optimization if we are within the code for a
-- discriminant check, since the whole point of such a check may
-- be to verify the condition on which the code below depends!