From d2f1e85b73e117ece7dd415c72dd500334e32c26 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 8 Mar 2024 14:05:21 +0000 Subject: [PATCH] Attribute dimension not checked for unconstrained array types Fixes #863 --- NEWS.md | 2 +- src/bounds.c | 2 +- test/bounds/issue863.vhd | 21 +++++++++++++++++++++ test/test_bounds.c | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/bounds/issue863.vhd diff --git a/NEWS.md b/NEWS.md index 95328c5d..e3683ad4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,7 +18,7 @@ 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). -- Resolved several other minor issues (#654, #854, #855). +- Resolved several other minor issues (#654, #854, #855, #863). ## Version 1.11.3 - 2024-02-04 - Fixed incorrect effective value when a signal has multiple sources due diff --git a/src/bounds.c b/src/bounds.c index d0c8c1ab..79997b1a 100644 --- a/src/bounds.c +++ b/src/bounds.c @@ -1283,7 +1283,7 @@ static void bounds_check_attr_ref(tree_t t) case ATTR_REVERSE_RANGE: if (tree_params(t) > 0) { type_t type = tree_type(tree_name(t)); - if (type_is_array(type) && !type_is_unconstrained(type)) { + if (type_is_array(type)) { tree_t dim_tree = tree_value(tree_param(t, 0)); int64_t dim; diff --git a/test/bounds/issue863.vhd b/test/bounds/issue863.vhd new file mode 100644 index 00000000..4bbcfa40 --- /dev/null +++ b/test/bounds/issue863.vhd @@ -0,0 +1,21 @@ +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 + begin + end procedure ; + +begin + + tb : process + begin + print("m length: " & integer'image(m'length(0))) ; -- Error + wait; + end process ; + +end architecture ; diff --git a/test/test_bounds.c b/test/test_bounds.c index b85dd71d..e021f107 100644 --- a/test/test_bounds.c +++ b/test/test_bounds.c @@ -724,6 +724,22 @@ START_TEST(test_cons1) } END_TEST +START_TEST(test_issue863) +{ + input_from_file(TESTDIR "/bounds/issue863.vhd"); + + const error_t expect[] = { + { 17, "invalid dimension 0 for type REAL_MATRIX" }, + { -1, NULL } + }; + expect_errors(expect); + + parse_check_and_simplify(T_ENTITY, T_ARCH); + + check_expected_errors(); +} +END_TEST + Suite *get_bounds_tests(void) { Suite *s = suite_create("bounds"); @@ -762,6 +778,7 @@ Suite *get_bounds_tests(void) tcase_add_test(tc_core, test_issue806); tcase_add_test(tc_core, test_issue819); tcase_add_test(tc_core, test_cons1); + tcase_add_test(tc_core, test_issue863); suite_add_tcase(s, tc_core); return s; -- 2.39.2