aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2022-06-09 05:33:54 +0200
committerTristan Gingold <tgingold@free.fr>2022-06-09 05:33:54 +0200
commit33740eb403c9dfbe3fc1f75b50de3000535da6bc (patch)
treef3979416a9fb601badf64ef89c38bf05a19188d6
parentd54d4128c0c7a58deed223dea03c13ce548166a5 (diff)
downloadghdl-33740eb403c9dfbe3fc1f75b50de3000535da6bc.tar.gz
ghdl-33740eb403c9dfbe3fc1f75b50de3000535da6bc.tar.bz2
ghdl-33740eb403c9dfbe3fc1f75b50de3000535da6bc.zip
vhdl-annotations: avoid a crash with subtype attribute in array.
Fix #2084
-rw-r--r--src/synth/elab-vhdl_types.adb5
-rw-r--r--src/synth/synth-vhdl_expr.adb7
-rw-r--r--src/vhdl/vhdl-annotations.adb9
3 files changed, 16 insertions, 5 deletions
diff --git a/src/synth/elab-vhdl_types.adb b/src/synth/elab-vhdl_types.adb
index ffddd20ae..b7f2da58f 100644
--- a/src/synth/elab-vhdl_types.adb
+++ b/src/synth/elab-vhdl_types.adb
@@ -220,6 +220,7 @@ package body Elab.Vhdl_Types is
function Synth_Array_Type_Definition
(Syn_Inst : Synth_Instance_Acc; Def : Node) return Type_Acc
is
+ El_St : constant Node := Get_Element_Subtype_Indication (Def);
El_Type : constant Node := Get_Element_Subtype (Def);
Ndims : constant Natural := Get_Nbr_Dimensions (Def);
Idx : Node;
@@ -227,7 +228,9 @@ package body Elab.Vhdl_Types is
Idx_Typ : Type_Acc;
Typ : Type_Acc;
begin
- Synth_Subtype_Indication_If_Anonymous (Syn_Inst, El_Type);
+ if Get_Kind (El_St) in Iir_Kinds_Subtype_Definition then
+ Synth_Subtype_Indication (Syn_Inst, El_Type);
+ end if;
El_Typ := Get_Subtype_Object (Syn_Inst, El_Type);
if El_Typ.Kind in Type_Nets and then Ndims = 1 then
diff --git a/src/synth/synth-vhdl_expr.adb b/src/synth/synth-vhdl_expr.adb
index 6b7672ae2..26555ff4d 100644
--- a/src/synth/synth-vhdl_expr.adb
+++ b/src/synth/synth-vhdl_expr.adb
@@ -2231,8 +2231,11 @@ package body Synth.Vhdl_Expr is
| Iir_Kind_Low_Array_Attribute
| Iir_Kind_Indexed_Name
| Iir_Kind_Integer_Literal =>
- -- The type of this attribute is the type of the index, which is
- -- not synthesized as a type (only as an index).
+ -- For array attributes: the type is the type of the index, which
+ -- is not synthesized as a type (only as an index).
+ --
+ -- Likewise for indexed names.
+ --
-- For integer_literal, the type is not really needed, and it
-- may be created by static evaluation of an array attribute.
Etype := Get_Base_Type (Etype);
diff --git a/src/vhdl/vhdl-annotations.adb b/src/vhdl/vhdl-annotations.adb
index 21224fe0e..8429d2dab 100644
--- a/src/vhdl/vhdl-annotations.adb
+++ b/src/vhdl/vhdl-annotations.adb
@@ -328,8 +328,13 @@ package body Vhdl.Annotations is
-- Create an annotation for the element type, as it can be
-- referenced by the implicit concat function definition for
-- concatenation with element.
- El := Get_Element_Subtype (Def);
- Annotate_Anonymous_Type_Definition (Block_Info, El);
+ El := Get_Element_Subtype_Indication (Def);
+ if Get_Kind (El) in Iir_Kinds_Subtype_Definition then
+ -- But only if it is a proper new subtype definition
+ -- (ie not a denoting name, or attributes like 'subtype).
+ El := Get_Element_Subtype (Def);
+ Annotate_Anonymous_Type_Definition (Block_Info, El);
+ end if;
-- Then for the array.
Create_Object_Info (Block_Info, Def, Kind_Type);