Tutorials
Verilog Inferred Latches: Find the Missing Assignment and Verify the Fix
Published · Updated
A combinational block that leaves an output unassigned on one branch asks that output to keep its previous value. That retained state is the clue to an inferred latch. Find the missing assignment first, then verify that the corrected behavior is actually the behavior the interface needs.
Make the retained value visible
always @* begin
if (en) q = d;
endWhen en is high, q follows d. When en is low, the block makes no assignment to q, so q retains a previous value. Adding always_comb changes the language construct and may improve diagnostics, but it does not supply the missing assignment. If storage was unintended, every combinational output needs a defined value on every path.
In the downloadable counterexample, the test sets en=1 and d=1, then sets en=0 and d=0. The incomplete block retains q=1. The corrected combinational block produces q=0. This is a small observation that makes the semantic difference visible without a large application around it.
For a case statement, inspect the default branch and every output assigned by the block. A default for one output does not cover another. Partial vector assignments can leave only some bits retaining state. Also inspect early conditional paths and assignments nested under enables.
Choose a default that matches the contract
always @* begin
q = 1'b0;
if (en) q = d;
endThe default zero is correct only if q must be zero when disabled. It is not a cosmetic fix for a warning. If the design needs q to retain state across clock cycles, express that behavior in an appropriate clocked process instead. If it intentionally needs a level-sensitive latch, describe and constrain that architecture deliberately.

The Mojo v3 photograph shows a physical FPGA development board. It is not the hardware used to run this example: the behavior here was checked in simulation, and the structure was inspected in generic synthesis. The lesson concerns RTL semantics rather than a claim about that board’s timing or tool support.
A state-machine next-state block often starts from a deliberate default such as next_state = state, while its output defaults follow the protocol. That does not justify q = q as a universal combinational default; self-retention preserves the storage behavior you were trying to remove.
Keep reset logic in the intended sequential state elements and review it with the reset-release guide. A reset branch added to an otherwise incomplete combinational block is not a replacement for full assignment coverage.
Check behavior and structure after the fix
The supplied latch test passed with Icarus Verilog from OSS CAD Suite 2026-11-15. Yosys processing of the two tiny modules produced a $dlatch cell for latch_bad and no $dlatch cell for latch_fixed. The download includes the source and commands so you can repeat both checks. These are generic synthesis results, not a Vivado implementation report.
iverilog -g2012 -s tb_latch -o latch.vvp latch_bad.v latch_fixed.v tb_latch.v
vvp latch.vvp
yosys -p "read_verilog latch_bad.v; proc; opt; stat"
yosys -p "read_verilog latch_fixed.v; proc; opt; stat"In the production tool, inspect the inferred primitives and warnings again after integrating the fix. Then rerun functional tests that cover enabled and disabled behavior. Removing a latch while changing the protocol is a regression, even if synthesis is quieter.
Use the branch worksheet to list outputs and assignment coverage; it does not parse arbitrary RTL or prove that a pasted block is latch-free. The counter testbench gives a larger example of checking behavior around disabled and reset conditions.
Once the RTL behavior is correct, review timing coverage and any remaining timing failures in the actual Vivado project.
Combinational assignment coverage checklist
Inputs and exported records stay in this browser. The check evaluates the assumptions you enter; it does not inspect your project files.
Use the worked values and equations above, or download the examples below. The interactive check requires JavaScript.
Watch the short disabled branch: retained q versus default q sequence
The sequence visualizes the stated example. It is not a hardware capture. The static figures and text above contain the same explanation.

Download both RTL versions and the testbench; include the unexpected synthesized cell and failing input sequence in a review.
Download the timing and RTL examples (ZIP) · Discuss this engineering task
The ZIP includes the clock and I/O examples, timing-audit commands, counter/latch/reset RTL and testbenches. Bring the relevant exported record to the enquiry; this page does not submit it automatically.
References and example scope
Documentation checked 16 November 2026. AMD examples use the cited 2024.1 documentation baseline. Vivado commands and vendor macros were not executed for this article. Counter, latch and illustrative reset tests were executed with Icarus Verilog; latch structure was checked with Yosys. See the included commands and validation record for the exact scope.