Skip to content

Verilog: wildcards in case items depend on the case kind - #2123

Merged
tautschnig merged 1 commit into
diffblue:mainfrom
kroening:kroening/case-wildcard-fix
Aug 30, 2026
Merged

Verilog: wildcards in case items depend on the case kind#2123
tautschnig merged 1 commit into
diffblue:mainfrom
kroening:kroening/case-wildcard-fix

Conversation

@kroening

Copy link
Copy Markdown
Collaborator

Summary

Fixes the KNOWNBUG introduced in #2122. Per IEEE 1800-2017 §12.5.1, the case items of a plain case statement are compared using 4-state equality (===): x and z in a case item are not wildcards. Only casex and casez have wildcards:

  • casez treats z (and ?) bits in a case item as wildcards.
  • casex treats x, z (and ?) bits in a case item as wildcards.

Previously the case items were masked irrespective of the kind of case statement, i.e., every case was effectively treated like casex.

Changes

  • src/verilog/verilog_synthesis.cpp: case_comparison now receives the case-statement kind and selects the wildcard bits accordingly (none for case, z-only for casez, x/z for casex). Non-wildcard positions are compared using 4-state equality (both aval and bval must match), which also correctly handles operands containing x/z. Added a PRECONDITION on the case kind.
  • src/verilog/verilog_synthesis_class.h: threaded the case kind through case_comparison and synth_case_values.
  • regression/verilog/case/case_wildcard1.desc: KNOWNBUGCORE.
  • regression/verilog/case/case_wildcard2.{sv,desc}: new test locking in the casex vs casez distinction.

Testing

  • make -C src builds clean.
  • make -C regression/verilog test: all case/*.desc pass, including both wildcard tests; no failures across the suite.
  • make -C regression/ebmc test and make -C regression/smv test: no failures.

The case items of a plain case statement are compared using 4-state
equality, per 1800-2017 section 12.5.1, i.e., x and z in a case item
are not wildcards. Only casex and casez have wildcards: casez treats
z (and ?) bits as wildcards, whereas casex treats x, z (and ?) bits
as wildcards.

The case items were previously masked irrespective of the kind of
case statement, i.e., every case was treated like casex. This is now
fixed: case_comparison receives the case kind and selects the
wildcard bits accordingly, comparing the non-wildcard positions using
4-state equality (both aval and bval must match).
@kroening
kroening force-pushed the kroening/case-wildcard-fix branch from 9e1e8eb to 5a00bc8 Compare August 29, 2026 19:22
@tautschnig
tautschnig merged commit 8aff64b into diffblue:main Aug 30, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants