Skip to content

Commit

Permalink
Fix usage of clocking arguments in sampled value system functions ins…
Browse files Browse the repository at this point in the history
…ide of always_comb blocks
  • Loading branch information
MikePopoloski committed Jun 24, 2022
1 parent 3f6e637 commit 6196181
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion source/binding/MiscExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,14 @@ ConstantValue LValueReferenceExpression::evalImpl(EvalContext& context) const {
}

Expression& ClockingEventExpression::fromSyntax(const ClockingPropertyExprSyntax& syntax,
const BindContext& context) {
const BindContext& argContext) {
// Clocking event expressions are only used in special system function calls,
// where they don't actually pass any time but instead tell the function which
// clock to use. We don't want usage inside of an always_comb to report an error
// about passing time, so clear out the context's procedure to avoid that.
BindContext context(argContext);
context.clearInstanceAndProc();

auto& comp = context.getCompilation();
auto& timing = TimingControl::bind(*syntax.event, context);

Expand Down
16 changes: 16 additions & 0 deletions tests/unittests/SystemFuncTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,3 +1074,19 @@ endmodule
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::ExpressionNotAssignable);
}

TEST_CASE("Sampled value functions with clocking in always_comb") {
auto tree = SyntaxTree::fromText(R"(
module top;
logic clk;
logic a, b;
always_comb begin
a = $past(b,,,@(posedge clk));
end
endmodule
)");

Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

0 comments on commit 6196181

Please sign in to comment.