aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-02-19 11:55:55 +0100
committerTristan Gingold <tgingold@free.fr>2023-02-19 12:30:49 +0100
commit3987fc5bb73352e696adf00dcadbb16b890b6199 (patch)
treebcb0cecc2c0e1b64ff608b31443aff35c4bb5f28
parent3ce8435531d9fe480a5eb47db923eaf9fa4c3273 (diff)
downloadghdl-3987fc5bb73352e696adf00dcadbb16b890b6199.tar.gz
ghdl-3987fc5bb73352e696adf00dcadbb16b890b6199.tar.bz2
ghdl-3987fc5bb73352e696adf00dcadbb16b890b6199.zip
vhdl-sem_decls(sem_object_type_from_value): refine.
Only use object type when it completes an unconstrained array type like in vhdl 93.
-rw-r--r--src/vhdl/vhdl-sem_decls.adb25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/vhdl/vhdl-sem_decls.adb b/src/vhdl/vhdl-sem_decls.adb
index 32b56a690..01a23517c 100644
--- a/src/vhdl/vhdl-sem_decls.adb
+++ b/src/vhdl/vhdl-sem_decls.adb
@@ -924,17 +924,32 @@ package body Vhdl.Sem_Decls is
return Deferred_Const;
end Get_Deferred_Constant;
+ -- Merge constraints from the subtype indication and the type of the
+ -- default value for constant declarations.
+ -- See LRM08 5.3.2.2 Index constraints and discrete ranges
procedure Sem_Object_Type_From_Value (Decl : Iir; Value : Iir)
is
Atype : constant Iir := Get_Type (Decl);
Value_Type : constant Iir := Get_Type (Value);
begin
- if not Is_Fully_Constrained_Type (Atype)
- and then not Is_Error (Value_Type)
+ if Is_Fully_Constrained_Type (Atype) then
+ -- No discussion, the type is defined by the subtype indication.
+ return;
+ end if;
+ if Is_Error (Value_Type) then
+ -- Don't try to merge types.
+ return;
+ end if;
+
+ -- Only use value type in the case of a vhdl-93 array completion.
+ if Get_Type_Staticness (Value_Type) >= Globally
+ and then Get_Kind (Value_Type) = Iir_Kind_Array_Subtype_Definition
+ and then Get_Element_Subtype (Atype) = Get_Element_Subtype (Value_Type)
+ and then Get_Index_Constraint_Flag (Value_Type)
+ and then (Get_Kind (Atype) = Iir_Kind_Array_Type_Definition
+ or else not Get_Index_Constraint_Flag (Atype))
then
- if Get_Type_Staticness (Value_Type) >= Globally then
- Set_Type (Decl, Value_Type);
- end if;
+ Set_Type (Decl, Value_Type);
end if;
end Sem_Object_Type_From_Value;