circt icon indicating copy to clipboard operation
circt copied to clipboard

[SV] Crash in `P/BPAssignOp` verifiers for `hw.inout` ports

Open mortbopet opened this issue 3 years ago • 4 comments

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

mortbopet avatar Jul 12 '23 07:07 mortbopet

Hi @mortbopet, I’m interested in looking into this issue. Is it still available to work on, or has someone already started on it?

shrav784 avatar Mar 02 '26 11:03 shrav784

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 in lib/Dialect/SV/SVOps.cpp.
  • Handle both net-like destination forms:
    • explicit sv.wire destinations
    • hw.module inout block arguments (hw::HWModuleLike port direction check)
  • Reused in both:
    • BPAssignOp::verify
    • PAssignOp::verify

Now the reproducer emits a proper verifier error instead of crashing.

Regression tests

Added to test/Dialect/SV/errors.mlir:

  • @PAssignInOutPort
  • @BPAssignInOutPort

thomasnormal avatar Mar 03 '26 11:03 thomasnormal

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 avatar Mar 03 '26 13:03 thomasnormal

@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

seldridge avatar Mar 06 '26 03:03 seldridge