Skip to content

Commit 6196181

Browse files
committed
Fix usage of clocking arguments in sampled value system functions inside of always_comb blocks
1 parent 3f6e637 commit 6196181

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

source/binding/MiscExpressions.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,14 @@ ConstantValue LValueReferenceExpression::evalImpl(EvalContext& context) const {
484484
}
485485

486486
Expression& ClockingEventExpression::fromSyntax(const ClockingPropertyExprSyntax& syntax,
487-
const BindContext& context) {
487+
const BindContext& argContext) {
488+
// Clocking event expressions are only used in special system function calls,
489+
// where they don't actually pass any time but instead tell the function which
490+
// clock to use. We don't want usage inside of an always_comb to report an error
491+
// about passing time, so clear out the context's procedure to avoid that.
492+
BindContext context(argContext);
493+
context.clearInstanceAndProc();
494+
488495
auto& comp = context.getCompilation();
489496
auto& timing = TimingControl::bind(*syntax.event, context);
490497

tests/unittests/SystemFuncTests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,3 +1074,19 @@ endmodule
10741074
REQUIRE(diags.size() == 1);
10751075
CHECK(diags[0].code == diag::ExpressionNotAssignable);
10761076
}
1077+
1078+
TEST_CASE("Sampled value functions with clocking in always_comb") {
1079+
auto tree = SyntaxTree::fromText(R"(
1080+
module top;
1081+
logic clk;
1082+
logic a, b;
1083+
always_comb begin
1084+
a = $past(b,,,@(posedge clk));
1085+
end
1086+
endmodule
1087+
)");
1088+
1089+
Compilation compilation;
1090+
compilation.addSyntaxTree(tree);
1091+
NO_COMPILATION_ERRORS;
1092+
}

0 commit comments

Comments
 (0)