From 8a512c7c11410b6c0eaf6f244cf84f2a96d0db54 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 8 Mar 2024 14:11:00 +0000 Subject: [PATCH] Allow any integer type for dimension attribute in --relaxed mode Issue #862 --- NEWS.md | 2 ++ src/sem.c | 26 +++++++++++++++--------- test/regress/gold/issue862.txt | 1 + test/regress/issue862.vhd | 37 ++++++++++++++++++++++++++++++++++ test/regress/testlist.txt | 1 + 5 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 test/regress/gold/issue862.txt create mode 100644 test/regress/issue862.vhd diff --git a/NEWS.md b/NEWS.md index e3683ad4..fcc6e47e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,8 @@ results in a non-zero exit code (#850). - Improvements to waveform dumping for signals with record types or types with non-locally-static bounds (#851, #852). +- The parameter for attributes with dimensions such as `'length(N)` may + be any integer type when `--relaxed` is passed (#862). - Resolved several other minor issues (#654, #854, #855, #863). ## Version 1.11.3 - 2024-02-04 diff --git a/src/sem.c b/src/sem.c index 621ebab7..b339ba1a 100644 --- a/src/sem.c +++ b/src/sem.c @@ -3960,15 +3960,23 @@ static bool sem_check_dimension_attr(tree_t t, nametab_t *tab) // universal_integer type_t uint = std_type(NULL, STD_UNIVERSAL_INTEGER); - if (!type_eq(tree_type(dim), uint)) { - diag_t *d = diag_new(DIAG_ERROR, tree_loc(dim)); - diag_printf(d, "dimension parameter of attribute %s must be a locally " - "static expression of type universal_integer", - istr(tree_ident(t))); - diag_hint(d, tree_loc(dim), "expression has type %s", - type_pp(tree_type(dim))); - diag_emit(d); - return false; + type_t dimtype = tree_type(dim); + if (!type_eq(dimtype, uint)) { + diag_t *d; + if (type_is_integer(dimtype)) + d = pedantic_diag(dim); + else + d = diag_new(DIAG_ERROR, tree_loc(dim)); + + if (d != NULL) { + diag_printf(d, "dimension parameter of attribute %s must be a locally " + "static expression of type universal_integer", + istr(tree_ident(t))); + diag_hint(d, tree_loc(dim), "expression has type %s", + type_pp(tree_type(dim))); + diag_emit(d); + return false; + } } if (!sem_locally_static(dim)) diff --git a/test/regress/gold/issue862.txt b/test/regress/gold/issue862.txt new file mode 100644 index 00000000..107140d4 --- /dev/null +++ b/test/regress/gold/issue862.txt @@ -0,0 +1 @@ +a is matrix 11 rows and 11 with elements of length 10 diff --git a/test/regress/issue862.vhd b/test/regress/issue862.vhd new file mode 100644 index 00000000..fd531ac7 --- /dev/null +++ b/test/regress/issue862.vhd @@ -0,0 +1,37 @@ +entity issue862 is +end entity ; + +architecture arch of issue862 is + + type bv_2d is array(integer range <>, integer range <>) of bit_vector ; + + constant ROWS : positive := 1 ; + constant COLS : positive := 2 ; + + -- Assume first index is rows, next index is columns + signal a : bv_2d(0 to 10, 0 to 10)(9 downto 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 ; + + procedure print(name : in string ; x : in bv_2d) is + begin + print( + name & " is matrix " & integer'image(x'length(ROWS)) & " rows and " & + integer'image(x'length(COLS)) & " with elements of length " & integer'image(x'element'length) + ) ; + end procedure ; + +begin + + tb : process + begin + print("a", a) ; + std.env.stop ; + end process ; + +end architecture ; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index 95ee6f06..d25a5c62 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -956,3 +956,4 @@ ename8 normal,2008 issue856 normal,2019 driver22 fail,gold,2019 vhpi12 normal,vhpi +issue862 normal,gold,2008,relaxed -- 2.39.2