[SV] Crash in `P/BPAssignOp` verifiers for `hw.inout` ports
In the SV P/BPAssignOp verifiers it is assumed that the target argument is defined by an op (isa used on getDefiningOp). Hence, in the case of a hw.inout input port, the verifier crashes.
i.e.:
hw.module @unsupported(%a: !hw.inout<i42>) {
%clock = hw.constant 1 : i1
%c42 = hw.constant 42 : i42
sv.alwaysff(posedge %clock) {
sv.passign %a, %c42 : i42
}
}
Hi @mortbopet, I’m interested in looking into this issue. Is it still available to work on, or has someone already started on it?
I reproduced this on current main and fixed it downstream in:
https://github.com/thomasnormal/circt/commit/563582646
Reproducer
module {
hw.module @unsupported(inout %a : i42) {
%clock = hw.constant 1 : i1
%c42 = hw.constant 42 : i42
sv.alwaysff(posedge %clock) {
sv.passign %a, %c42 : i42
}
hw.output
}
}
Before fix: circt-opt crashed in circt::sv::PAssignOp::verify().
Root cause
Verifier used:
isa<sv::WireOp>(getDest().getDefiningOp())
For module block arguments (inout ports), getDefiningOp() is null, which caused the verifier crash.
Fix
- Added
isProceduralNetDest(Value)helper inlib/Dialect/SV/SVOps.cpp. - Handle both net-like destination forms:
- explicit
sv.wiredestinations hw.moduleinoutblock arguments (hw::HWModuleLikeport direction check)
- explicit
- Reused in both:
BPAssignOp::verifyPAssignOp::verify
Now the reproducer emits a proper verifier error instead of crashing.
Regression tests
Added to test/Dialect/SV/errors.mlir:
@PAssignInOutPort@BPAssignInOutPort
Rechecked this on current main and could not reproduce the verifier crash.
Reproducer (current syntax):
hw.module @unsupported(inout %a : i42) {
%clock = hw.constant 1 : i1
%c42 = hw.constant 42 : i42
sv.alwaysff(posedge %clock) {
sv.passign %a, %c42 : i42
}
hw.output
}
Current behavior: emits a verifier error (no crash):
Verilog disallows procedural assignment to a net type
There is dedicated in-tree verifier coverage for this path:
test/Dialect/SV/errors.mlir@PAssignInOutPort@BPAssignInOutPort
@thomasnormal, @thomasahle: Due to current CIRCT project policy, we are unable to accept patches from the thomasnormal/circt fork.
For others: please do not upstream any patches from the thomasnormal/circt fork. Additionally, recognize that any comments made by the @thomasnormal account appear to be from one or more AI agents.
For more information, please see this Discourse post: https://discourse.llvm.org/t/circt-project-policy-on-contributions-from-thomasnormal-circt-fork/90075