VERILOG2015: Non-void function return values should not be ignored
Summary
| Reliability | Security | Maintainability | Code attribute | Effort to fix | Tags |
|---|---|---|---|---|---|
| HIGH | - | - | Intentionality | Logical | 10min | synthesis, vscode, linter, simulation, dead-code |
Description
Noncompliant code example
module top(input x, output reg y);
function int foo;
return 1;
endfunction
function int bar;
return 0;
endfunction
always @ (posedge x) begin
foo(); // Noncompliant
bar(); // Noncompliant
end
endmodule
Compliant solution
module top(input x, output reg y);
function int foo;
return 1;
endfunction
function int bar;
return 0;
endfunction
always @ (posedge x) begin
y <= foo(); // Compliant: Return value is used
void'(bar()); // Compliant: Explicit cast to 'void'
end
endmodule
A non-void function is invoked without inspecting its return value.
Capture the result or explicitly cast the call to void if it is the expected behavior.
Parameters
No parameters.