Skip to content

Commit d69e890

Browse files
authored
Fix getDPIExports() dropping exports that share a C identifier (MikePopoloski#1924)
- Remove the shouldRecordResolved skip in checkDPIMethods so every resolved DPI export is recorded, not just the first per C identifier - Keep the signature check and the same-scope DPIExportDuplicateCId error - Add a test for a module instantiated twice under one C identifier Fixes MikePopoloski#1923
1 parent 8390e98 commit d69e890

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

source/ast/Compilation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,6 @@ void Compilation::checkDPIMethods(std::span<const SubroutineSymbol* const> dpiIm
20452045

20462046
auto [nameIt, nameInserted] = nameMap.emplace(cId, &sub);
20472047
if (!nameInserted) {
2048-
shouldRecordResolved = false;
20492048
if (!checkSignaturesMatch(sub, *nameIt->second)) {
20502049
auto& diag = scope->addDiag(diag::DPISignatureMismatch, syntax->name.range());
20512050
diag << cId;

tests/unittests/ast/SubroutineTests.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,36 @@ endmodule
326326
CHECK(exports[1].syntax->c_identifier.valueText() == "my_f2");
327327
}
328328

329+
TEST_CASE("Compilation collects DPI exports from each instance") {
330+
auto tree = SyntaxTree::fromText(R"(
331+
module Sub #(parameter int ID = 0);
332+
int id;
333+
export "DPI-C" function read_id;
334+
function int read_id(); return id; endfunction
335+
initial id = ID;
336+
endmodule
337+
338+
module Top;
339+
Sub #(.ID(10)) m0();
340+
Sub #(.ID(20)) m1();
341+
endmodule
342+
)");
343+
344+
Compilation compilation;
345+
compilation.addSyntaxTree(tree);
346+
NO_COMPILATION_ERRORS;
347+
348+
// The single export directive elaborates into two distinct instances. Both
349+
// are valid targets, selected at call time via svSetScope, so both must be
350+
// reported even though they share a C identifier.
351+
auto exports = compilation.getDPIExports();
352+
REQUIRE(exports.size() == 2);
353+
CHECK(exports[0].subroutine->getHierarchicalPath() == "Top.m0.read_id");
354+
CHECK(exports[0].cIdentifier == "read_id");
355+
CHECK(exports[1].subroutine->getHierarchicalPath() == "Top.m1.read_id");
356+
CHECK(exports[1].cIdentifier == "read_id");
357+
}
358+
329359
TEST_CASE("DPI signature checking") {
330360
auto tree = SyntaxTree::fromText(R"(
331361
import "DPI-C" function int foo(int a, output b);

0 commit comments

Comments
 (0)