From 4428c9a6c68f4d7f152e585714b34a519cd578ab Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 5 Dec 2022 21:09:01 +0000 Subject: [PATCH] Fix parsing of array element constraints with "open". Issue #580 --- NEWS.md | 2 +- contrib/install-osvvm.sh | 2 +- src/parse.c | 10 +++++----- src/sem.c | 3 ++- test/parse/issue580.vhd | 16 ++++++++++++++++ test/test-osvvm.tcl | 2 +- test/test_parse.c | 28 ++++++++++++++++++++++++++++ 7 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 test/parse/issue580.vhd diff --git a/NEWS.md b/NEWS.md index e932fd0f..9d726af7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -21,7 +21,7 @@ - `libffi` is now a build-time dependency. - Negation of the smallest negative value of a type such as `-integer'left` now produces an error. -- Default OSVVM version updated to 2022.10. +- Default OSVVM version updated to 2022.11. ## Version 1.7.2 - 2022-10-16 - Fixed build on FreeBSD/arm (#534). diff --git a/contrib/install-osvvm.sh b/contrib/install-osvvm.sh index 6abc4318..81c004e5 100755 --- a/contrib/install-osvvm.sh +++ b/contrib/install-osvvm.sh @@ -13,7 +13,7 @@ if ! command -v tclsh &>/dev/null; then exit 1 fi -git_wrapper https://github.com/osvvm/OsvvmLibraries 2022.10 +git_wrapper https://github.com/osvvm/OsvvmLibraries 2022.11 [ -d $NVC_INSTALL_DEST ] || mkdir -p $NVC_INSTALL_DEST diff --git a/src/parse.c b/src/parse.c index f4849506..851e2844 100644 --- a/src/parse.c +++ b/src/parse.c @@ -3769,13 +3769,13 @@ static void p_array_constraint(type_t type, type_t base) type_add_constraint(type, p_record_constraint(base)); break; } - else { + else type_add_constraint(type, p_index_constraint(base)); - // Base type may not actually be an array due to earlier errors - if (base != NULL && type_is_array(base)) - base = type_elem(base); - } + // Base type may not actually be an array due to earlier errors + if (base != NULL && type_is_array(base)) + base = type_elem(base); + } while (peek() == tLPAREN); } diff --git a/src/sem.c b/src/sem.c index 4d8df531..a1e7f6cd 100644 --- a/src/sem.c +++ b/src/sem.c @@ -403,7 +403,8 @@ static bool sem_check_subtype_helper(tree_t decl, type_t type, nametab_t *tab) if (!sem_check_constraint(cons, elem, tab)) return false; - if (i + 1 < ncon && tree_subkind(cons) == C_INDEX) + const constraint_kind_t consk = tree_subkind(cons); + if (i + 1 < ncon && (consk == C_INDEX || consk == C_OPEN)) elem = type_elem(elem); } diff --git a/test/parse/issue580.vhd b/test/parse/issue580.vhd new file mode 100644 index 00000000..5fed9dbd --- /dev/null +++ b/test/parse/issue580.vhd @@ -0,0 +1,16 @@ +entity issue580 is +end entity; + +architecture test of issue580 is + type rec_t is record + bits : bit_vector; + end record; + + type rec_array_t is array (natural range <>) of rec_t; + + subtype sub_t is rec_array_t(open)(bits(1 to 3)); -- OK + + signal s1 : sub_t(1 to 4); -- OK + signal s2 : sub_t; -- Error +begin +end architecture; diff --git a/test/test-osvvm.tcl b/test/test-osvvm.tcl index 64989550..d722b236 100644 --- a/test/test-osvvm.tcl +++ b/test/test-osvvm.tcl @@ -4,7 +4,7 @@ # Note: tcllib is required for OSVVM # known good snapshot -set OsvvmLibraries_tag "2022.10" +set OsvvmLibraries_tag "2022.11" exec git clone --branch $OsvvmLibraries_tag --recurse-submodules -j8 https://github.com/OSVVM/OsvvmLibraries.git >@ stdout 2>@ stdout source OsvvmLibraries/Scripts/StartNVC.tcl diff --git a/test/test_parse.c b/test/test_parse.c index 23774e65..fbe3065b 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -5080,6 +5080,33 @@ START_TEST(test_osvvm7) } END_TEST +START_TEST(test_issue580) +{ + set_standard(STD_08); + + input_from_file(TESTDIR "/parse/issue580.vhd"); + + const error_t expect[] = { + { 14, "declaration of signal S2 cannot have unconstrained type SUB_T" }, + { -1, NULL } + }; + expect_errors(expect); + + tree_t e = parse(); + fail_if(e == NULL); + fail_unless(tree_kind(e) == T_ENTITY); + lib_put(lib_work(), e); + + tree_t a = parse(); + fail_if(a == NULL); + fail_unless(tree_kind(a) == T_ARCH); + + fail_unless(parse() == NULL); + + check_expected_errors(); +} +END_TEST + Suite *get_parse_tests(void) { Suite *s = suite_create("parse"); @@ -5179,6 +5206,7 @@ Suite *get_parse_tests(void) tcase_add_test(tc_core, test_issue568); tcase_add_test(tc_core, test_issue569); tcase_add_test(tc_core, test_osvvm7); + tcase_add_test(tc_core, test_issue580); suite_add_tcase(s, tc_core); return s; -- 2.39.2