From e129122f0f6909bbc59075678ea72d744612e69e Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 26 Oct 2022 20:25:42 +0100 Subject: [PATCH] Avoid error with null-range aggregate. Issue #552 --- src/bounds.c | 3 +++ test/bounds/nullrange.vhd | 12 ++++++++++++ test/test_bounds.c | 13 +++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 test/bounds/nullrange.vhd diff --git a/src/bounds.c b/src/bounds.c index 9e9bd8bf..7617af7e 100644 --- a/src/bounds.c +++ b/src/bounds.c @@ -185,6 +185,9 @@ static bool bounds_check_index(tree_t index, tree_t ref, type_t type, range_kind_t kind, const char *what, int64_t low, int64_t high) { + if (low > high) + return true; // Null range allows any index + int64_t folded; unsigned folded_u; if (folded_int(index, &folded)) { diff --git a/test/bounds/nullrange.vhd b/test/bounds/nullrange.vhd new file mode 100644 index 00000000..8fd5647d --- /dev/null +++ b/test/bounds/nullrange.vhd @@ -0,0 +1,12 @@ +entity test is +end entity test; +architecture beh of test is + signal sig : bit_vector(-1 downto 0); + signal sig2 : bit_vector(0 to -1); +begin + process(sig,sig2) + begin + sig <= (sig'range => '0'); -- OK + sig2 <= (sig2'range => '0'); -- OK + end process; +end architecture beh; diff --git a/test/test_bounds.c b/test/test_bounds.c index 28aec9ae..5696796f 100644 --- a/test/test_bounds.c +++ b/test/test_bounds.c @@ -568,6 +568,18 @@ START_TEST(test_driver1) } END_TEST +START_TEST(test_nullrange) +{ + input_from_file(TESTDIR "/bounds/nullrange.vhd"); + + tree_t a = parse_check_and_simplify(T_ENTITY, T_ARCH); + fail_unless(error_count() == 0); + + bounds_check(a); + fail_if_errors(); +} +END_TEST + Suite *get_bounds_tests(void) { Suite *s = suite_create("bounds"); @@ -596,6 +608,7 @@ Suite *get_bounds_tests(void) tcase_add_test(tc_core, test_issue477b); tcase_add_test(tc_core, test_case3); tcase_add_test(tc_core, test_driver1); + tcase_add_test(tc_core, test_nullrange); suite_add_tcase(s, tc_core); return s; -- 2.39.2