diff --git a/src/V3LinkResolve.cpp b/src/V3LinkResolve.cpp index cb268fa1e..9d5630141 100644 --- a/src/V3LinkResolve.cpp +++ b/src/V3LinkResolve.cpp @@ -221,7 +221,8 @@ class LinkResolveVisitor final : public VNVisitor { letp->user2(false); return; } - if (nodep->taskp() && (nodep->taskp()->dpiContext() || nodep->taskp()->dpiExport())) { + if (nodep->taskp() && !nodep->scopeNamep() + && (nodep->taskp()->dpiContext() || nodep->taskp()->dpiExport())) { nodep->scopeNamep(new AstScopeName{nodep->fileline(), false}); } } diff --git a/test_regress/t/t_dpi_context.py b/test_regress/t/t_dpi_context.py index 8f4de8825..bcdb2941d 100755 --- a/test_regress/t/t_dpi_context.py +++ b/test_regress/t/t_dpi_context.py @@ -11,7 +11,7 @@ import vltest_bootstrap test.scenarios('simulator') -test.compile(v_flags2=["t/t_dpi_context_c.cpp"]) +test.compile(v_flags2=["t/t_dpi_context_c.cpp", "--debug", "-no-dump-tree"]) test.execute() diff --git a/test_regress/t/t_dpi_context.v b/test_regress/t/t_dpi_context.v index b0e11a23f..d246db028 100644 --- a/test_regress/t/t_dpi_context.v +++ b/test_regress/t/t_dpi_context.v @@ -32,6 +32,7 @@ module sub (input integer inst); import "DPI-C" context function int dpic_save(int value); import "DPI-C" context function int dpic_restore(); import "DPI-C" context function int unsigned dpic_getcontext(); + import "DPI-C" context function int unsigned dpic_get1(); int result; @@ -63,6 +64,11 @@ module sub (input integer inst); if (dpic_restore() != 23+inst) $stop; endtask + function automatic int call_dpic_get1; + int res = dpic_get1(); + return res; + endfunction + int unsigned cntxt1; int unsigned cntxt2; @@ -74,6 +80,7 @@ module sub (input integer inst); end // svContext should be the context of the function declaration, not the context of the function call if (cntxt1 != cntxt2) $stop; + if (call_dpic_get1() != 1) $stop; end endmodule diff --git a/test_regress/t/t_dpi_context_c.cpp b/test_regress/t/t_dpi_context_c.cpp index 9025e9407..9d27e8fd8 100644 --- a/test_regress/t/t_dpi_context_c.cpp +++ b/test_regress/t/t_dpi_context_c.cpp @@ -42,6 +42,7 @@ extern int dpic_line(); extern int dpic_save(int value); extern int dpic_restore(); extern unsigned dpic_getcontext(); +extern unsigned dpic_get1(); } #endif @@ -151,6 +152,8 @@ unsigned dpic_getcontext() { return (unsigned)(uintptr_t)scope; } +unsigned dpic_get1() { return 1; } + void dpic_final() { static int s_once = 0; if (s_once++) return;