Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when trying to access 'length(0) for multi-dimensional array #863

Closed
bpadalino opened this issue Mar 7, 2024 · 0 comments
Closed

Comments

@bpadalino
Copy link
Contributor

When trying to access the attribute 'length(0) for a 2-d array, a crash occurs.

entity test is
end entity ;

architecture arch of test is

    type real_matrix is array (natural range <>, natural range <>) of real ;
    constant m : real_matrix := ( (1.0, 2.0, 3.0, 4.0), (2.0, 3.0, 4.0, 5.0) ) ;

    procedure print(x : in string) is
        variable l : std.textio.line ;
    begin
        std.textio.write(l, x) ;
        std.textio.writeline(std.textio.output, l) ;
    end procedure ;

begin

    tb : process
    begin
        print("m length: " & integer'image(m'length(0))) ;
        std.env.stop ;
    end process ;

end architecture ;
$ nvc --std=2008 -a attribute_value.vhdl -e test -r

Name       WORK.TEST.TB
Kind       process
Context    WORK.TEST
Blocks     2
Registers  14
Types      15
Variables  0
Begin
   0: return 
   1: r0 := context upref 1             // P<WORK.TEST>
      r1 := const 109                   // 0..255 => 109
      r2 := const 32                    // 0..255 => 32
      r3 := const 108                   // 0..255 => 108
      r4 := const 101                   // 0..255 => 101
      r5 := const 110                   // 0..255 => 110
      r6 := const 103                   // 0..255 => 103
      r7 := const 116                   // 0..255 => 116
      r8 := const 104                   // 0..255 => 104
      r9 := const 58                    // 0..255 => 58
      r10 := const [r1,r2,r3,r4,r5,r6,r7,r8,r9,r2] // [10] : 0..255 => 0..255
      r11 := address of r10             // @<0..255> => 0..255
      r12 := var upref 1, M             // @<[*, *] : %> => %
      r13 := load indirect r12          // [*, *] : % => %
      invalid := uarray len r13 dim -1   <----

** Fatal: invalid dimension -1
[0x5644f5fa0e9c] ../src/diag.c:1011 diag_femit
[0x5644f5fa0e9c] ../src/diag.c:1036 diag_emit
[0x5644f5edbdb2] ../src/util.c:585 fatal_trace
[0x5644f5f8f862] ../src/vcode.c:4636 emit_uarray_len
[0x5644f5f6d75c] ../src/lower.c:4884 lower_attr_ref
[0x5644f5f6d75c] ../src/lower.c:5249 lower_expr.lto_priv.0
[0x5644f5f8729d] ../src/lower.c:12618 lower_rvalue
[0x5644f5f68de4] ../src/lower.c:4799 lower_attr_param.lto_priv.0
[0x5644f5f6d808] ../src/lower.c:4989 lower_attr_ref
[0x5644f5f6d808] ../src/lower.c:5249 lower_expr.lto_priv.0
[0x5644f5f8729d] ../src/lower.c:12618 lower_rvalue
[0x5644f5f5bcd1] ../src/lower.c:2042 lower_flatten_concat
[0x5644f5f6296c] ../src/lower.c:2053 lower_concat.lto_priv.0
[0x5644f5f6c39f] ../src/lower.c:5223 lower_expr.lto_priv.0
[0x5644f5f8729d] ../src/lower.c:12618 lower_rvalue
[0x5644f5f61def] ../src/lower.c:1127 lower_subprogram_arg.lto_priv.0
[0x5644f5f6f02f] ../src/lower.c:6530 lower_pcall
[0x5644f5f6f8b5] ../src/lower.c:7378 lower_sequence.lto_priv.0
[0x5644f5f44869] ../src/lower.c:11352 elab_stmts.lto_priv.0
[0x5644f5f3ceb9] ../src/elab.c:1489 elab_architecture.lto_priv.0
[0x5644f6009209] ../src/elab.c:2091 elab_top_level.constprop.0
[0x5644f5f41d90] ../src/elab.c:2154 elab
[0x5644f5ee4a4a] ../src/nvc.c:464 elaborate
[0x5644f5ee1c9f] ../src/nvc.c:1921 process_command
[0x5644f5ee20dc] ../src/nvc.c:1041 init_cmd
[0x5644f5ee20dc] ../src/nvc.c:1935 process_command
[0x5644f5ed9845] ../src/nvc.c:2059 main

When accessing a real_vector, the error appears:

** Error: invalid dimension 0 for type REAL_VECTOR
    > attribute_value.vhdl:19
    |                                                                                 
 19 |         print("v length: " & integer'image(v'length(0))) ;
    |                                                     ^
@nickg nickg closed this as completed in d2f1e85 Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant