From 19c9526512aba74a506f847f3800f38163320743 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 29 Dec 2023 20:37:57 +0000 Subject: [PATCH] Fix crash with aliased enumeration literal in case choice Fixes #819 --- src/common.c | 6 ++---- test/bounds/issue819.vhd | 39 +++++++++++++++++++++++++++++++++++++++ test/test_bounds.c | 11 +++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 test/bounds/issue819.vhd diff --git a/src/common.c b/src/common.c index d3638912..74acaf28 100644 --- a/src/common.c +++ b/src/common.c @@ -1487,10 +1487,8 @@ unsigned get_case_choice_char(tree_t value, int depth) { switch (tree_kind(value)) { case T_STRING: - if (depth < tree_chars(value)) { - tree_t ch = tree_char(value, depth); - return tree_pos(tree_ref(ch)); - } + if (depth < tree_chars(value)) + return assume_int(tree_char(value, depth)); else return ~0; // Out of bounds diff --git a/test/bounds/issue819.vhd b/test/bounds/issue819.vhd new file mode 100644 index 00000000..9d449ce2 --- /dev/null +++ b/test/bounds/issue819.vhd @@ -0,0 +1,39 @@ +package my_logic is + type std_ulogic is ('0', '1'); + type std_ulogic_vector is array (natural range <>) of std_ulogic; + type unsigned is array (natural range <>) of std_ulogic; + type signed is array (natural range <>) of std_ulogic; +end package; + +------------------------------------------------------------------------------- + +use work.my_logic.all; + +package uCPUtypes is + alias logic is std_ulogic; + alias logic_vec is std_ulogic_vector; +end package uCPUtypes; + +------------------------------------------------------------------------------- + +use work.uCPUtypes.all; + +entity uCPU is +end entity uCPU; + +architecture RTL of uCPU is + + signal rom_data : logic_vec(11 downto 0); + +begin + +--------------- combination logic ---------------- + + process (rom_data) is + begin + case rom_data(11 downto 10) is + when "00" => null; + when others => null; + end case; + end process; +end architecture RTL; diff --git a/test/test_bounds.c b/test/test_bounds.c index 9614d13f..c190670a 100644 --- a/test/test_bounds.c +++ b/test/test_bounds.c @@ -693,6 +693,16 @@ START_TEST(test_issue806) } END_TEST +START_TEST(test_issue819) +{ + input_from_file(TESTDIR "/bounds/issue819.vhd"); + + parse_check_and_simplify(T_PACKAGE, T_PACKAGE, T_ENTITY, T_ARCH); + + fail_if_errors(); +} +END_TEST + Suite *get_bounds_tests(void) { Suite *s = suite_create("bounds"); @@ -729,6 +739,7 @@ Suite *get_bounds_tests(void) tcase_add_test(tc_core, test_case5); tcase_add_test(tc_core, test_issue800); tcase_add_test(tc_core, test_issue806); + tcase_add_test(tc_core, test_issue819); suite_add_tcase(s, tc_core); return s; -- 2.39.2