New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn on mixing non-blocking and blocking assignments to the same variable #1400
Comments
Your variable |
I see, sorry, I was not aware that Yosys is following (the superseded) 1364.1-2002 (which I am not familiar with). Instead, I had SystemVerilog in mind. Just taking a quick look into 1800-2017, I found one example (Example 3, on p. 239) containing assignments of both kinds to the same variable (in an But of course, this does not matter much as SystemVerilog is a different language than the language Yosys claims to support... because I guess this is out of scope for |
I don't think that example is relevant, it's not two examples in the same always block and seeing which one "wins" but instead one initial block (that runs at the first timestep) and an always block (which runs later on) so there is no conflict. FWIW, trying the design in a commercial SystemVerilog tool, after renaming the module as |
I'll copy the example here to make sure we are talking about the same example:
According to (System)Verilog's simulation semantics, As for the error generated by the (non-Yosys) SystemVerilog tool: I think this is reasonable behaviour. I think either producing an error or compiling the program in a semantics-preserving way according to the simulation semantics are both valid options. Silently miscompiling the program is more confusing behaviour than those two in my opinion (there are probably a lot of other (simple) Verilog programs where the compiler will not preserve semantics... but still). But this is of course a design decision: I.e., is it the user's responsibility to not write strange programs, or should the compiler warn the user if it is given strange programs. (Seems that Yosys approach is to try to follow 1364.1-2002 and provide fire missiles semantics (undefined behaviour in C terminology) for strange programs?) |
Please note that Yosys is not a simulator, and thus is not really a full implementation of Verilog semantics — by design, it can only support synthesisable code, and non-blocking assignment to an output port in a clocked always block can not be represented by synthesis. While this is not a priority of yosys (see http://www.clifford.at/yosys/faq.html point 5), we can add an error or warning for this case (mixed blocking and non-blocking assignments). |
Steps to reproduce the issue
Hi, I noticed the following miscompilation bug. Not sure if it is considered interesting or not:
Consider the following Verilog program:
Compile using the following:
With this, I get the following program as output:
Expected behaviour
I expected the output Verilog program to have the same behaviour as the input Verilog program, in particular I expected
out
to evaluate to0
each clock cycle.Actual behaviour
The output Verilog program sets
out
to1
(instead of0
).I am aware that the input program is strange/ugly (style guides often mention not to mix different assignments to the same variable etc.), but I expected some kind of warning from the compiler rather than the compiler silently miscompiling the program (or simply that the compiler would correctly compile the program).
The text was updated successfully, but these errors were encountered: