title: How to use procedures with generic lists in VHDL-2008?
body: <p>I refactored some working VHDL code to use a <code>procedure</code> with a generic list, and now it segfaults in Modelsim (2020.1).</p>
  <p>The procedure's generic list includes a <code>type</code> and another <code>procedure</code>.</p>
  <p>The segfault seems to be happening because a <code>std.textio.line</code> (which is an <code>access</code> type) becomes <code>NULL</code> when it is passed into the procedure indicated in the generic list.</p>
  <p>I have provided below what I think is minimal code to reproduce the problem. Note that the seemingly irrelevant <code>dummy_t</code> type (which is mapped to <code>integer</code>) is required to reproduce the error. If I delete this dummy type (and value) then the <code>line</code> doesn't become <code>NULL</code>.</p>
  <pre class="lang-vhdl prettyprint-override"><code>use std.textio.all;
  
  package test_pkg is
      
      -- Some external procedure
      procedure p0(L : inout line; x : integer);
      
      -- Uninstantiated generic procedure
      procedure p1_generic
          generic (type dummy_t; procedure p2(L : inout line; x : dummy_t))
          parameter (L : inout line; x : dummy_t);
      
      -- Instance of generic procedure
      procedure p1 is new p1_generic
          generic map(dummy_t =&gt; integer, p2 =&gt; p0);
      
  end package;
  
  package body test_pkg is
      
      -- Some external procedure
      procedure p0(L : inout line; x : integer) is
      begin
          assert L /= NULL report &quot;p0: L is NULL.&quot; severity Failure;
      end;
      
      -- Uninstantiated generic procedure
      procedure p1_generic
          generic (
              type dummy_t;
              procedure p2(L : inout line; x : dummy_t)
          )
          parameter (L : inout line; x : dummy_t) is
      begin
          assert L /= NULL report &quot;p1: L is NULL.&quot; severity Failure;
          p2(L, x);
      end;
  
  end package body;
  
  ---------------------------------------------------------------------------------------------------
  -- Testbench
  ---------------------------------------------------------------------------------------------------
  use std.textio.all;
  use work.test_pkg.all;
  
  entity testbench is
  end testbench;
  
  architecture arch of testbench is
  begin
      
      process
          variable Line_v : line := new string'(&quot;Hello&quot;);
      begin
          p1(Line_v, 123);
          deallocate(Line_v);
          wait;
      end process;
      
  end architecture;
  </code></pre>
  <p>I saved this in a file named test_pkg.vhd and simulated it as follows:</p>
  <pre class="lang-none prettyprint-override"><code>vlib lib
  vcom -2008 -work lib test_pkg.vhd
  vsim lib.testbench
  run -all
  </code></pre>
  <p>This error is repeatable on multiple runs (<code>restart -f; run -all</code>):</p>
  <pre class="lang-none prettyprint-override"><code># ** Fatal: (SIGSEGV) Bad handle or reference.
  #    Time: 0 ps  Iteration: 0  Process: /testbench/line__54 File: test_pkg.vhd
  # Fatal error in Process line__54 at test_pkg.vhd line 57
  </code></pre>
  <p>(This suggests L was not NULL immediately before being output from <code>p0</code>, but then it became somehow corrupted after being returned <code>p0</code> -&gt; <code>p1</code> -&gt; testbench).</p>
  <p>I tried printing out <code>L.all</code> inside each procedure and I get different garbage in each case:</p>
  <pre class="lang-none prettyprint-override"><code>èíJ]pè%K]èð]‹Eè‹P‹
  ‹Eè‹P‹
  </code></pre>
  <p>If I recompile with <code>vcom -2008 -work lib test_pkg.vhd</code> then I get a different failure:</p>
  <pre class="lang-none prettyprint-override"><code># ** Failure: p0: L is NULL.
  #    Time: 0 ps  Iteration: 0  Process: /testbench/line__54 File: test_pkg.vhd
  </code></pre>
  <p>(This suggests L was not NULL immediately before being passed into <code>p0</code>, but then became NULL immediately inside that procedure).</p>
  <p>What am I doing wrong here?</p>