Skip to content

Commit

Permalink
Fix lookup of checker formal ports from within assertion instances
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Mar 2, 2025
1 parent 09a9e69 commit cdceaf1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
18 changes: 16 additions & 2 deletions source/ast/expressions/MiscExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,10 +1182,24 @@ Expression& AssertionInstanceExpression::bindPort(const Symbol& symbol, SourceRa
inst = inst->argDetails;

// The only way to reference an assertion port should be from within
// an assertion instance, so we should always find it here.
// an assertion or checker instance.
auto it = inst->argumentMap.find(&symbol);
if (it == inst->argumentMap.end())
if (it == inst->argumentMap.end()) {
// Walk through our previous assertion contexts to see if one of
// them is a checker instance, in which case this argument might
// be a reference to a checker port.
auto ctx = inst->prevContext;
while (ctx) {
inst = ctx->assertionInstance;
if (!inst || (inst->symbol && inst->symbol->kind == SymbolKind::Checker))
return bindPort(symbol, range, ctx->resetFlags(instanceCtx.flags));

ctx = inst->prevContext;
}

SLANG_ASSERT(false);
return badExpr(comp, nullptr);
}

auto& formal = symbol.as<AssertionPortSymbol>();
auto& type = formal.declaredType.getType();
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/ast/AssertionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1974,8 +1974,8 @@ endchecker
module m;
logic clk;
my_check c1(clk, 1);
op_test1 t1(clk, 1, 2, 3);
op_test2 t2(clk, 1, 2, 3);
op_test1 t1(clk, 1, 1, 3);
op_test2 t2(clk, 1, 1, 3);
endmodule
)");

Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/parsing/VisitorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ TEST_CASE("Visit all file") {
v.visitDefault(elem);
}));

CHECK(count == 1794);
CHECK(count == 1812);

compilation.getAllDiagnostics();
compilation.freeze();
Expand Down

0 comments on commit cdceaf1

Please sign in to comment.