diff options
| author | Tristan Gingold <tgingold@free.fr> | 2023-01-04 19:45:56 +0100 | 
|---|---|---|
| committer | Tristan Gingold <tgingold@free.fr> | 2023-01-04 19:45:56 +0100 | 
| commit | f254978c5531b28d8b4f9a1d674b3465ec363b6e (patch) | |
| tree | 6869a73da84085bef98e8421e97d8e5fa7332f2e | |
| parent | b91a9fbbef7328f6f041f4ddda01dbbd7e156cfb (diff) | |
| download | ghdl-f254978c5531b28d8b4f9a1d674b3465ec363b6e.tar.gz ghdl-f254978c5531b28d8b4f9a1d674b3465ec363b6e.tar.bz2 ghdl-f254978c5531b28d8b4f9a1d674b3465ec363b6e.zip | |
synth: detect null access dereference, fix offset.
| -rw-r--r-- | src/synth/synth-vhdl_expr.adb | 8 | ||||
| -rw-r--r-- | src/synth/synth-vhdl_stmts.adb | 15 | 
2 files changed, 19 insertions, 4 deletions
| diff --git a/src/synth/synth-vhdl_expr.adb b/src/synth/synth-vhdl_expr.adb index 49fa4a546..7cf295417 100644 --- a/src/synth/synth-vhdl_expr.adb +++ b/src/synth/synth-vhdl_expr.adb @@ -710,10 +710,16 @@ package body Synth.Vhdl_Expr is             | Iir_Kind_Dereference =>              declare                 Val : Valtyp; +               Acc : Heap_Index;                 Obj : Memtyp;              begin                 Val := Synth_Expression (Syn_Inst, Get_Prefix (Name)); -               Obj := Elab.Vhdl_Heap.Synth_Dereference (Read_Access (Val)); +               Acc := Read_Access (Val); +               if Acc = Null_Heap_Index then +                  Error_Msg_Synth (Syn_Inst, Name, "null access dereference"); +                  return No_Valtyp; +               end if; +               Obj := Elab.Vhdl_Heap.Synth_Dereference (Acc);                 return Create_Value_Memtyp (Obj);              end;           when others => diff --git a/src/synth/synth-vhdl_stmts.adb b/src/synth/synth-vhdl_stmts.adb index 098448ba2..8cc09b290 100644 --- a/src/synth/synth-vhdl_stmts.adb +++ b/src/synth/synth-vhdl_stmts.adb @@ -268,14 +268,23 @@ package body Synth.Vhdl_Stmts is             | Iir_Kind_Dereference =>              declare                 Acc : Memtyp; +               Idx : Heap_Index;              begin                 Synth_Assignment_Prefix                   (Syn_Inst, Get_Prefix (Pfx), Dest_Base, Dest_Typ, Dest_Off);                 Acc := (Dest_Typ, Dest_Base.Val.Mem + Dest_Off.Mem_Off); -               Dest_Base := Create_Value_Memtyp -                 (Elab.Vhdl_Heap.Synth_Dereference (Read_Access (Acc))); -               Dest_Typ := Dest_Base.Typ; +               Idx := Read_Access (Acc); +               if Idx = Null_Heap_Index then +                  Error_Msg_Synth (Syn_Inst, Pfx, "null access dereference"); +                  Dest_Base := No_Valtyp; +                  Dest_Typ := Dest_Typ.Acc_Acc; +               else +                  Dest_Base := Create_Value_Memtyp +                    (Elab.Vhdl_Heap.Synth_Dereference (Idx)); +                  Dest_Typ := Dest_Base.Typ; +               end if;                 Dest_Dyn := No_Dyn_Name; +               Dest_Off := No_Value_Offsets;              end;           when others =>              Error_Kind ("synth_assignment_prefix", Pfx); | 
