Skip to content
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

Queue poping wrong value when otherwise unused #2512

Closed
nanduraj1 opened this issue Aug 24, 2020 · 1 comment
Closed

Queue poping wrong value when otherwise unused #2512

nanduraj1 opened this issue Aug 24, 2020 · 1 comment
Assignees
Labels
area: data-types Issue involves data-types resolution: fixed Closed; fixed

Comments

@nanduraj1
Copy link

Thanks for taking the time to report this.

Can you attach an example that shows the issue? (Must be openly licensed, ideally in test_regress format.)
queue_test.tar.gz

Test

module tb_top(
    input clk
);

    logic q [$];
    int cycle = 0;

    always@(posedge clk) begin
        q.push_front(1'b1);
        cycle <= cycle + 1'b1;
    end

    always@(posedge clk) begin
        if(cycle == 'd1) begin
            if (q.pop_back() == 1'b1) $display("Passed");
            else begin
                $display("Failed");
                $fatal;
            end
        end
    end

endmodule
#include "verilated.h"
#include "Vtb_top.h"
#include <ctime>

double sc_time_stamp() {return 2 * 1e9;}

int main(int argc, char **argv, char **env)
{
    Vtb_top* top = new Vtb_top;
    for (uint8_t d1=0, d2=0; true; d1++, d2++) {
        top->clk = !top->clk;
        top->eval();
        if (Verilated::gotFinish()) break;
    }
    top->final();
    exit(0);
}

Output

make
verilator -Mdir build_verilator tb_top.sv  -cc -no-decoration -O3 -CFLAGS -Wno-attributes -CFLAGS -O2  \
 +define+SIM_VERILATOR  -top-module tb_top -exe main.cpp
cd ./build_verilator && \
make -j -f Vtb_top.mk Vtb_top && \
cd -
make[1]: Entering directory '/home/ubuntu/Work/misc_verilog/verilator_exp/build_verilator'
ccache g++  -I.  -MMD -I/home/ubuntu/softwares/verilator/include -I/home/ubuntu/softwares/verilator/include/vltstd -DVM_COVERAGE=0 -DVM_SC=0 -DVM_TRACE=0 -Wno-sign-compare -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-unused-variable -Wno-shadow     -Wno-attributes -O2  -Os -c -o main.o ../main.cpp
ccache g++  -I.  -MMD -I/home/ubuntu/softwares/verilator/include -I/home/ubuntu/softwares/verilator/include/vltstd -DVM_COVERAGE=0 -DVM_SC=0 -DVM_TRACE=0 -Wno-sign-compare -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-unused-variable -Wno-shadow     -Wno-attributes -O2  -Os -c -o verilated.o /home/ubuntu/softwares/verilator/include/verilated.cpp
/usr/bin/perl /home/ubuntu/softwares/verilator/bin/verilator_includer -DVL_INCLUDE_OPT=include Vtb_top.cpp Vtb_top__Slow.cpp Vtb_top__Syms.cpp > Vtb_top__ALL.cpp
ccache g++  -I.  -MMD -I/home/ubuntu/softwares/verilator/include -I/home/ubuntu/softwares/verilator/include/vltstd -DVM_COVERAGE=0 -DVM_SC=0 -DVM_TRACE=0 -Wno-sign-compare -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-unused-variable -Wno-shadow     -Wno-attributes -O2  -Os -c -o Vtb_top__ALL.o Vtb_top__ALL.cpp
ar -cr Vtb_top__ALL.a Vtb_top__ALL.o
ranlib Vtb_top__ALL.a
g++    main.o verilated.o Vtb_top__ALL.a      -o Vtb_top
make[1]: Leaving directory '/home/ubuntu/Work/misc_verilog/verilator_exp/build_verilator'
/home/ubuntu/Work/misc_verilog/verilator_exp
./build_verilator/Vtb_top
Failed
[2000000000] %Error: tb_top.sv:18: Assertion failed in TOP.tb_top
%Error: tb_top.sv:18: Verilog $stop
Aborting...
Makefile:53: recipe for target 'sim_verilator' failed
make: *** [sim_verilator] Aborted (core dumped)

What 'verilator --version' are you using? Did you try it with the git master version?

verilator version : Verilator 4.040 2020-08-15 rev v4.040-9-gc4f7bd6

Would you be willing to try to fix Verilator yourself with assistance?
yes

@nanduraj1 nanduraj1 added the new New issue not seen by maintainers label Aug 24, 2020
@wsnyder wsnyder self-assigned this Aug 24, 2020
@wsnyder wsnyder added area: data-types Issue involves data-types status: ready Issue is ready for someone to fix; then goes to 'status: assigned' and removed new New issue not seen by maintainers labels Aug 24, 2020
@wsnyder
Copy link
Member

wsnyder commented Aug 24, 2020

pop_back isn't correctly seen by verilator as using the queue, it only changes the queue, so Verilator removes q as it thinks it is unused. Will need some refactoring to fix this, so stay tuned.

Meanwhile, as a workaround for the moment, use

           $display("Failed %d", q.size);

@wsnyder wsnyder changed the title Queue poping wrong value initially Queue poping wrong value when otherwise unused Nov 7, 2020
@wsnyder wsnyder added resolution: fixed Closed; fixed and removed status: ready Issue is ready for someone to fix; then goes to 'status: assigned' labels Nov 7, 2020
@wsnyder wsnyder closed this as completed Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: data-types Issue involves data-types resolution: fixed Closed; fixed
Projects
None yet
Development

No branches or pull requests

2 participants