From 3a505ad29b7223dba87f298383932c4d553e8cf0 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 17 Sep 2023 20:29:20 +0100 Subject: [PATCH] Fix crash overriding predefined function in package body only Issue #760 --- NEWS.md | 2 ++ src/names.c | 3 ++- test/parse/issue760.vhd | 11 +++++++++++ test/test_parse.c | 23 +++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/parse/issue760.vhd diff --git a/NEWS.md b/NEWS.md index 1d5c8f04e..6f8a3b3e0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,8 @@ - Fixed a memory leak in the `--print-deps` command. - Fixed a crash when evaluating globally static expressions during elaboration with coverage enabled (#759). +- Fixed an analysis crash where a predefined function for a type + declared in a package is overridden in the package body only (#760). ## Version 1.10.2 - 2023-08-20 - Fixed a crash due to an array bounds check being incorrectly optimised diff --git a/src/names.c b/src/names.c index df5a03ba4..342230a50 100644 --- a/src/names.c +++ b/src/names.c @@ -797,7 +797,8 @@ static symbol_t *make_visible(scope_t *s, ident_t name, tree_t decl, && (tree_flags(dd->tree) & TREE_F_PREDEFINED)) { // Allow pre-defined operators be to hidden by // user-defined subprograms in the same region - tree_set_flag(dd->tree, TREE_F_HIDDEN); + if (!tree_frozen(dd->tree)) + tree_set_flag(dd->tree, TREE_F_HIDDEN); // Will be deleted later dd->visibility = HIDDEN; } else if (is_forward_decl(decl, dd->tree)) { diff --git a/test/parse/issue760.vhd b/test/parse/issue760.vhd new file mode 100644 index 000000000..2ad024d86 --- /dev/null +++ b/test/parse/issue760.vhd @@ -0,0 +1,11 @@ +package issue760 is + type t_array is array (natural range <>) of integer; +end package; + +package body issue760 is + -- Hides predef defined in package header + impure function to_string (x : t_array) return string is + begin + return ""; + end function; +end package body; diff --git a/test/test_parse.c b/test/test_parse.c index 228503591..8ff30c3d8 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -5665,6 +5665,28 @@ START_TEST(test_issue751) } END_TEST +START_TEST(test_issue760) +{ + set_standard(STD_19); + + input_from_file(TESTDIR "/parse/issue760.vhd"); + + tree_t p = parse(); + fail_if(p == NULL); + fail_unless(tree_kind(p) == T_PACKAGE); + + lib_put(lib_work(), p); + + tree_t b = parse(); + fail_if(b == NULL); + fail_unless(tree_kind(b) == T_PACK_BODY); + + fail_unless(parse() == NULL); + + fail_if_errors(); +} +END_TEST + Suite *get_parse_tests(void) { Suite *s = suite_create("parse"); @@ -5784,6 +5806,7 @@ Suite *get_parse_tests(void) tcase_add_test(tc_core, test_issue727); tcase_add_test(tc_core, test_visibility8); tcase_add_test(tc_core, test_issue751); + tcase_add_test(tc_core, test_issue760); suite_add_tcase(s, tc_core); return s;