From 53094cd00b2ea92c43147858f9d87a91ba4095cf Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 20 Mar 2024 21:14:30 +0000 Subject: [PATCH] Make sure entity is rewritten before architecture. Issue #867 --- src/object.c | 11 +++++------ src/object.h | 25 ++++++++++--------------- test/simp/issue867.vhd | 26 ++++++++++++++++++++++++++ test/test_bounds.c | 2 +- test/test_simp.c | 21 +++++++++++++++++++++ 5 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 test/simp/issue867.vhd diff --git a/src/object.c b/src/object.c index 648b1860..5dfca152 100644 --- a/src/object.c +++ b/src/object.c @@ -82,18 +82,17 @@ typedef struct _object_arena { #define ITEM_NUMBER (I_NUMBER) static const char *item_text_map[] = { - "I_IDENT", "I_VALUE", "I_SEVERITY", "I_MESSAGE", "I_TARGET", - "I_LITERAL", "I_IDENT2", "I_DECLS", "I_STMTS", "I_PORTS", - "I_GENERICS", "I_PARAMS", "I_GENMAPS", "I_WAVES", "I_CONDS", + "I_IDENT", "I_VALUE", "I_PRIMARY", "I_GENERICS", "I_PORTS", + "I_DECLS", "I_STMTS", "I_TARGET", "I_IVAL", "I_IDENT2", + "I_SEVERITY", "I_PARAMS", "I_GENMAPS", "I_WAVES", "I_CONDS", "I_TYPE", "I_SUBKIND", "I_DELAY", "I_REJECT", "I_POS", "I_REF", "I_FILE_MODE", "I_ASSOCS", "I_CONTEXT", "I_TRIGGERS", "I_PARTS" , "I_CLASS", "I_RANGES", "I_NAME", "I_PRAGMAS", "I_DVAL", "I_SPEC", "I_FOREIGN", "I_INDEXES", "I_BASE", "I_ELEM", "I_DESIGNATED", "I_DATATYPE", "I_RESOLUTION", "I_RESULT", "I_UNITS", "I_LITERALS", "I_DIMS", "I_FIELDS", "I_CLOCK", - "I_GUARD", "????", "I_CHARS", "I_CONSTR", "I_FLAGS", - "I_TEXT", "I_LEFT", "I_RIGHT", "I_NUMBER", "????", - "????", "????", "????", "????", "I_PRIMARY", + "I_GUARD", "I_REPEAT", "I_CHARS", "I_CONSTR", "I_FLAGS", + "I_TEXT", "I_LEFT", "I_RIGHT", "I_NUMBER", "I_MESSAGE", }; static object_class_t *classes[4]; diff --git a/src/object.h b/src/object.h index 9246c23a..ef69c4f7 100644 --- a/src/object.h +++ b/src/object.h @@ -36,15 +36,15 @@ typedef uint64_t imask_t; #define I_IDENT ONE_HOT(0) #define I_VALUE ONE_HOT(1) -#define I_SEVERITY ONE_HOT(2) -#define I_MESSAGE ONE_HOT(3) -#define I_TARGET ONE_HOT(4) -#define I_IVAL ONE_HOT(5) -#define I_IDENT2 ONE_HOT(6) -#define I_DECLS ONE_HOT(7) -#define I_STMTS ONE_HOT(8) -#define I_PORTS ONE_HOT(9) -#define I_GENERICS ONE_HOT(10) +#define I_PRIMARY ONE_HOT(2) +#define I_GENERICS ONE_HOT(3) +#define I_PORTS ONE_HOT(4) +#define I_DECLS ONE_HOT(5) +#define I_STMTS ONE_HOT(6) +#define I_TARGET ONE_HOT(7) +#define I_IVAL ONE_HOT(8) +#define I_IDENT2 ONE_HOT(9) +#define I_SEVERITY ONE_HOT(10) #define I_PARAMS ONE_HOT(11) #define I_GENMAPS ONE_HOT(12) #define I_WAVES ONE_HOT(13) @@ -88,12 +88,7 @@ typedef uint64_t imask_t; #define I_LEFT ONE_HOT(51) #define I_RIGHT ONE_HOT(52) #define I_NUMBER ONE_HOT(53) -// Unused ONE_HOT(54) -// Unused ONE_HOT(55) -// Unused ONE_HOT(56) -// Unused ONE_HOT(57) -// Unused ONE_HOT(58) -#define I_PRIMARY ONE_HOT(59) +#define I_MESSAGE ONE_HOT(54) enum { OBJECT_TAG_TREE = 0, diff --git a/test/simp/issue867.vhd b/test/simp/issue867.vhd new file mode 100644 index 00000000..8fe56e06 --- /dev/null +++ b/test/simp/issue867.vhd @@ -0,0 +1,26 @@ +package pkg is + function dummy_function return natural; +end package pkg; + +package body pkg is + function dummy_function return natural is + begin + return 4; + end function; +end package body pkg; + +library work; +use work.pkg.all; + +entity ent is + -- Should get rewritten before signals below + constant CONST : natural := dummy_function; +end entity ent; + +architecture arch of ent is + signal s0 : bit; + signal s1 : bit_vector(CONST downto 0); + signal s2 : bit_vector(CONST downto 0); +begin + s2 <= s1 and (s1'range => s0); +end architecture arch; diff --git a/test/test_bounds.c b/test/test_bounds.c index e021f107..750d6f66 100644 --- a/test/test_bounds.c +++ b/test/test_bounds.c @@ -114,8 +114,8 @@ START_TEST(test_bounds2) { 56, "value 10 outside of R range 0 to 1 for constant C2"}, { 59, "value 30 outside of SUBINT range 1 to 10 for parameter A"}, { 63, "'c' outside of CHARACTER range 'a' to 'b' for parameter A" }, - { 73, "value 2 outside of INTEGER range 0 to 1 for port P2"}, { 70, "value 20 outside of INTEGER range 10 downto 0 for generic G2"}, + { 73, "value 2 outside of INTEGER range 0 to 1 for port P2"}, { 79, "value 5.0999999999999996 outside of REAL range 0 to 5"}, { 95, "assignment delays must be in ascending time order"}, { 96, "assignment delays must be in ascending time order"}, diff --git a/test/test_simp.c b/test/test_simp.c index f4b2c3f1..21dfeee5 100644 --- a/test/test_simp.c +++ b/test/test_simp.c @@ -1679,6 +1679,26 @@ START_TEST(test_issue821) } END_TEST +START_TEST(test_issue867) +{ + input_from_file(TESTDIR "/simp/issue867.vhd"); + + tree_t top = run_elab(); + + tree_t ent = tree_stmt(top, 0); + tree_t s1 = search_decls(ent, ident_new("S1"), 0); + tree_t r = range_of(tree_type(s1), 0); + fail_unless(tree_subkind(r) == RANGE_DOWNTO); + + int64_t low, high; + fail_unless(folded_bounds(r, &low, &high)); + fail_unless(low == 0); + fail_unless(high == 4); + + fail_if_errors(); +} +END_TEST + Suite *get_simp_tests(void) { Suite *s = suite_create("simplify"); @@ -1745,6 +1765,7 @@ Suite *get_simp_tests(void) tcase_add_test(tc_core, test_order2); tcase_add_test(tc_core, test_issue812); tcase_add_test(tc_core, test_issue821); + tcase_add_test(tc_core, test_issue867); suite_add_tcase(s, tc_core); return s; -- 2.39.2