From 1a9b3405077589ec395162f4c727244543937658 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 1 Dec 2022 21:38:14 +0000 Subject: [PATCH] Fix error analysing OSVVM xMiiPhyRxTransmitter.vhd. Issue #577 --- src/jit/jit-llvm.c | 3 +- src/parse.c | 12 ++------ test/parse/osvvm7.vhd | 68 +++++++++++++++++++++++++++++++++++++++++++ test/test_parse.c | 53 +++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 test/parse/osvvm7.vhd diff --git a/src/jit/jit-llvm.c b/src/jit/jit-llvm.c index a82b054e..c9a6fa4c 100644 --- a/src/jit/jit-llvm.c +++ b/src/jit/jit-llvm.c @@ -921,12 +921,11 @@ static LLVMValueRef cgen_get_value(llvm_obj_t *obj, cgen_block_t *cgb, case JIT_VALUE_EXIT: return llvm_int32(obj, value.exit); case JIT_VALUE_HANDLE: - if (cgb->func->cpool != NULL) + if (cgb->func->cpool != NULL && value.handle != JIT_HANDLE_INVALID) return cgen_rematerialise_handle(obj, cgb, value.handle); else return llvm_int32(obj, value.handle); case JIT_ADDR_ABS: - assert(obj->ctor == NULL || value.int64 == 0); return llvm_ptr(obj, (void *)(intptr_t)value.int64); case JIT_VALUE_FOREIGN: if (cgb->func->cpool != NULL) diff --git a/src/parse.c b/src/parse.c index 700e8389..ac96aba1 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1856,16 +1856,8 @@ static tree_t fcall_to_conv_func(tree_t value) static bool instantiate_should_copy_type(type_t type, void *__ctx) { - switch (type_kind(type)) { - case T_GENERIC: - return true; - case T_ENUM: - case T_PHYSICAL: - // Need to generate type-specific helpers like 'IMAGE - return true; - default: - return false; - } + // Types declared in instantiated packages must be distict + return type_kind(type) != T_SUBTYPE; } static bool instantiate_should_copy_tree(tree_t t, void *__ctx) diff --git a/test/parse/osvvm7.vhd b/test/parse/osvvm7.vhd new file mode 100644 index 00000000..d5e35822 --- /dev/null +++ b/test/parse/osvvm7.vhd @@ -0,0 +1,68 @@ +package ScoreboardGenericPkg1 is + generic ( + type ExpectedType ; + type ActualType + ) ; + + type ScoreboardIdType is record + Id : integer ; + end record ScoreboardIdType ; + + impure function NewID ( + Name : String + ) return ScoreboardIDType ; + +end ScoreboardGenericPkg1 ; + +package body ScoreboardGenericPkg1 is + + impure function NewID ( + Name : String + ) return ScoreboardIDType is + begin + return (id => 0); + end function NewID ; + +end ScoreboardGenericPkg1 ; + +------------------------------------------------------------------------------- + +package ScoreBoardPkg_slv1 is new work.ScoreboardGenericPkg1 + generic map ( + ExpectedType => bit_vector, + ActualType => bit_vector + ) ; + +------------------------------------------------------------------------------- + +package ScoreBoardPkg_int1 is new work.ScoreboardGenericPkg1 + generic map ( + ExpectedType => integer, + ActualType => integer + ) ; + +------------------------------------------------------------------------------- + +use work.ScoreboardPkg_slv1.all ; +use work.ScoreboardPkg_int1.all ; + +entity xMiiPhyRxTransmitter is +end entity xMiiPhyRxTransmitter ; +architecture behavioral of xMiiPhyRxTransmitter is + + signal DataFifo : work.ScoreboardPkg_slv1.ScoreboardIDType ; + signal MetaFifo : work.ScoreboardPkg_int1.ScoreboardIDType ; + +begin + + ------------------------------------------------------------ + -- Initialize alerts + ------------------------------------------------------------ + Initialize : process + begin + DataFifo <= NewID("DataFifo") ; + MetaFifo <= NewID("MetaFifo") ; + wait ; + end process Initialize ; + +end architecture behavioral ; diff --git a/test/test_parse.c b/test/test_parse.c index 9fcaba01..23774e65 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -5028,6 +5028,58 @@ START_TEST(test_issue569) } END_TEST +START_TEST(test_osvvm7) +{ + set_standard(STD_08); + input_from_file(TESTDIR "/parse/osvvm7.vhd"); + + lib_t work = lib_work(); + + tree_t p = parse(); + fail_if(p == NULL); + fail_unless(tree_kind(p) == T_PACKAGE); + lib_put(work, p); + + tree_t b = parse(); + fail_if(b == NULL); + fail_unless(tree_kind(b) == T_PACK_BODY); + lib_put(work, b); + + tree_t i1 = parse(); + fail_if(i1 == NULL); + fail_unless(tree_kind(i1) == T_PACK_INST); + lib_put(work, i1); + + tree_t i2 = parse(); + fail_if(i2 == NULL); + fail_unless(tree_kind(i2) == T_PACK_INST); + lib_put(work, i2); + + ident_t name = ident_new("SCOREBOARDIDTYPE"); + tree_t d1 = search_decls(i1, name, 0); + fail_if(d1 == NULL); + fail_unless(tree_kind(d1) == T_TYPE_DECL); + tree_t d2 = search_decls(i2, name, 0); + fail_if(d2 == NULL); + fail_unless(tree_kind(d2) == T_TYPE_DECL); + + fail_if(type_eq(tree_type(d1), tree_type(d2))); + + tree_t e = parse(); + fail_if(e == NULL); + fail_unless(tree_kind(e) == T_ENTITY); + lib_put(work, e); + + tree_t a = parse(); + fail_if(a == NULL); + fail_unless(tree_kind(a) == T_ARCH); + + fail_unless(parse() == NULL); + + fail_if_errors(); +} +END_TEST + Suite *get_parse_tests(void) { Suite *s = suite_create("parse"); @@ -5126,6 +5178,7 @@ Suite *get_parse_tests(void) tcase_add_test(tc_core, test_issue539); tcase_add_test(tc_core, test_issue568); tcase_add_test(tc_core, test_issue569); + tcase_add_test(tc_core, test_osvvm7); suite_add_tcase(s, tc_core); return s; -- 2.39.2