From d1273a9b9e36a521dad8e0586a1bf02b67c6203b Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Tue, 26 Mar 2024 23:05:59 +0000 Subject: [PATCH] Suppress error for hidden declarations with --relaxed. Fixes #870 --- src/names.c | 6 +++++- test/parse/issue870.vhd | 16 ++++++++++++++++ test/test_parse.c | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/parse/issue870.vhd diff --git a/src/names.c b/src/names.c index 48d0a6ed..02478869 100644 --- a/src/names.c +++ b/src/names.c @@ -1231,6 +1231,8 @@ void hide_name(nametab_t *tab, ident_t name) const symbol_t *exist = symbol_for(tab->top_scope, name); if (exist == NULL || exist->owner == tab->top_scope) return; + else if (opt_get_int(OPT_RELAXED)) + return; symbol_t *sym = local_symbol_for(tab->top_scope, name); @@ -1746,8 +1748,10 @@ tree_t resolve_name(nametab_t *tab, const loc_t *loc, ident_t name) } diag_t *d = diag_new(DIAG_ERROR, loc); - if (hidden > 0 && hidden == sym->ndecls) + if (hidden > 0 && hidden == sym->ndecls) { diag_printf(d, "declaration of %s is hidden", istr(name)); + diag_hint(d, NULL, "the $bold$--relaxed$$ option suppresses this error"); + } else if (overload == 0) diag_printf(d, "multiple conflicting visible declarations of %s", istr(name)); diff --git a/test/parse/issue870.vhd b/test/parse/issue870.vhd new file mode 100644 index 00000000..98c7ab03 --- /dev/null +++ b/test/parse/issue870.vhd @@ -0,0 +1,16 @@ +entity ent is +generic ( + SEED1 : natural := 500 +); +port ( + clk : in bit +); +end entity ent; + +architecture arch of ent is +begin + process(clk) + variable seed1 : natural := SEED1; -- OK (relaxed rules) + begin + end process; +end architecture arch; diff --git a/test/test_parse.c b/test/test_parse.c index daec6f7e..079a78d0 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -6181,6 +6181,25 @@ START_TEST(test_issue848) } END_TEST +START_TEST(test_issue870) +{ + opt_set_int(OPT_RELAXED, 1); + + input_from_file(TESTDIR "/parse/issue870.vhd"); + + 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_if_errors(); +} +END_TEST + Suite *get_parse_tests(void) { Suite *s = suite_create("parse"); @@ -6318,6 +6337,7 @@ Suite *get_parse_tests(void) tcase_add_test(tc_core, test_issue837); tcase_add_test(tc_core, test_issue845); tcase_add_test(tc_core, test_issue848); + tcase_add_test(tc_core, test_issue870); suite_add_tcase(s, tc_core); return s; -- 2.39.2