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; +}