Skip to content

Crash with unconstrained record #1178

@cwyki

Description

@cwyki

Hi,
following code produces either a crash or (sometimes) a fatal error:

library ieee;
use ieee.std_logic_1164.all;

entity reproducer is
end entity reproducer;

architecture rtl of reproducer is
  type slv_vector_t is array (natural range <>) of std_logic_vector;
  type rec is record
    vector : slv_vector_t;
    -- vector : slv_vector_t(0 TO 1)(0 DOWNTO 0); -- constraint record works
  end record;
  function get_rec return rec is
    variable a : slv_vector_t(0 TO 0)(0 DOWNTO 0) := (0 => "0");
    variable b : slv_vector_t(0 TO 0)(0 DOWNTO 0) := (0 => "1");
  begin
    return (vector => (slv_vector_t'(0 => "0") & slv_vector_t'(0 => "1"))); -- crash when 'vector' is unconstrained
    -- return (vector => a & b); -- crash when 'vector' is unconstrained
  end function;  
begin
    main : process
        variable val : std_logic_vector(0 DOWNTO 0);
    begin
        val := get_rec.vector(0);
        report to_string(val);
        wait;        
    end process;
end architecture;

Results in:

$ nvc -a reproducer.vhd -e reproducer -r
*** Caught signal 11 (SEGV_MAPERR) [address=0x562b42b30b60, ip=0x562969e4cba8] ***

[0x562969da4c0d] 
[0x7f6d1b3ca32f] (/usr/lib/x86_64-linux-gnu/libc.so.6) 
[0x562969e4cba8] 
[0x562969e4cded] 
[0x562969e4cf78] 
[0x562969e2b822] 
[0x562969e2bc7c] 
[0x562969e349f9] 
[0x562969e35314] 
[0x562969e34d0a] 
[0x562969e5222a] 
[0x562969e374f1] 
[0x562969e38acf] 
[0x562969e0b4a8] 
[0x562969e028fe] 
[0x562969ef25c3] 
[0x562969da0003] 
[0x562969d9d158] 
[0x562969d9da32] 
[0x562969d98cb1] 
[0x7f6d1b3af1c9] (/usr/lib/x86_64-linux-gnu/libc.so.6) 
[0x7f6d1b3af28a] (/usr/lib/x86_64-linux-gnu/libc.so.6) __libc_start_main
[0x562969d9a304] 

nvc 1.15.2 (2fe12d4) (Using LLVM 18.1.3) [x86_64-pc-linux-gnu]

Please report this bug at https://github.com/nickg/nvc/issues

When you try a few times, the output might also look like:

$ nvc -a reproducer.vhd -e reproducer -r
** Fatal: 0ms+0: value length -1480589314 does not match variable VAL length 2
    > reproducer.vhd:22
    |
 22 |         val := get_rec.vector(0); -- not okay
    |         ^^^

The number value length -1480589314 changes every call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions