From 61961817af9ba59f87e2d07cad03b2464975f09e Mon Sep 17 00:00:00 2001 From: MikePopoloski Date: Fri, 24 Jun 2022 07:32:34 -0700 Subject: [PATCH] Fix usage of clocking arguments in sampled value system functions inside of always_comb blocks --- source/binding/MiscExpressions.cpp | 9 ++++++++- tests/unittests/SystemFuncTests.cpp | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/source/binding/MiscExpressions.cpp b/source/binding/MiscExpressions.cpp index f9df0d6a0..d6889e988 100644 --- a/source/binding/MiscExpressions.cpp +++ b/source/binding/MiscExpressions.cpp @@ -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); diff --git a/tests/unittests/SystemFuncTests.cpp b/tests/unittests/SystemFuncTests.cpp index ee50187c9..437a88aca 100644 --- a/tests/unittests/SystemFuncTests.cpp +++ b/tests/unittests/SystemFuncTests.cpp @@ -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; +}