with Sem_Util; use Sem_Util;
with Sem_Warn; use Sem_Warn;
with Sinfo; use Sinfo;
+with Snames; use Snames;
with Stand; use Stand;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
-- Given a node N for a variable whose Current_Value field is set.
-- If the node is for a discrete type, replaces the node with a
-- copy of the referenced value. This provides a limited form of
- -- value propagation for variables which are initialized and have
- -- not been modified at the time of reference. The call has no
- -- effect if the Current_Value refers to a conditional with a
+ -- value propagation for variables which are initialized or assigned
+ -- not been further modified at the time of reference. The call has
+ -- no effect if the Current_Value refers to a conditional with a
-- condition other than equality.
procedure Expand_Discriminant (N : Node_Id);
CS := Scope (CS);
-- Otherwise, the reference is dubious, and we cannot be
- -- sure that it is safe to do the replacement. Note in
- -- particular, in a loop (except for the special case
- -- tested above), we cannot safely do a replacement since
- -- there may be an assignment at the bottom of the loop
- -- that will affect a reference at the top of the loop.
+ -- sure that it is safe to do the replacement.
else
exit;
begin
if True
+ -- No replacement if value raises constraint error
+
+ and then Nkind (CV) /= N_Raise_Constraint_Error
+
-- Do this only for discrete types
and then Is_Discrete_Type (T)
-- issue that they do not get replaced when they could be).
and then Nkind (Parent (N)) /= N_Pragma_Argument_Association
+
+ -- Same for Asm_Input and Asm_Output attribute references
+
+ and then not (Nkind (Parent (N)) = N_Attribute_Reference
+ and then
+ (Attribute_Name (Parent (N)) = Name_Asm_Input
+ or else
+ Attribute_Name (Parent (N)) = Name_Asm_Output))
then
-- Case of Current_Value is a compile time known value
or else
Ekind (E) = E_Out_Parameter)
and then Present (Current_Value (E))
- and then Nkind (Current_Value (E)) /= N_Raise_Constraint_Error
then
Expand_Current_Value (N);
P_Comp_Ref :=
Make_Selected_Component (Loc,
Prefix =>
- Unchecked_Convert_To (Parm_Type,
- New_Reference_To (Addr_Ent, Loc)),
+ Make_Explicit_Dereference (Loc,
+ Unchecked_Convert_To (Parm_Type,
+ New_Reference_To (Addr_Ent, Loc))),
Selector_Name =>
New_Reference_To (Entry_Component (Ent_Formal), Loc));