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

Fix empty if removes function with side effect #3131

Closed
agrobman opened this issue Sep 13, 2021 · 3 comments
Closed

Fix empty if removes function with side effect #3131

agrobman opened this issue Sep 13, 2021 · 3 comments
Labels
area: wrong runtime result Issue involves an incorrect runtine result from Verilated model resolution: fixed Closed; fixed

Comments

@agrobman
Copy link

I have following verilog:

module plus;
int kuku;

initial begin
    if($value$plusargs("kuku=%d", kuku));
    $display("kuku=%d", kuku);
    $finish;
end

endmodule

sim_main.cpp:

  #include "Vvalueplusarg.h"
  #include "verilated.h"
  int main(int argc, char** argv, char** env) {
      Verilated::commandArgs(argc, argv);
      Vvalueplusarg* top = new Vvalueplusarg{""};
      while (!Verilated::gotFinish()) { top->eval(); }
      top->final();
      delete top;
      return 0;
  }

compiling:

verilator --cc --build --exe valueplusarg.sv sim_main.cpp

running:

% obj_dir/Vvalueplusarg +kuku=5
kuku=          0
- valueplusarg.sv:7: Verilog $finish

should print '5'

if I change verilog

if($value$plusargs("kuku=%d", kuku)) $display(kuku);

it picks up the kuku value ...

our verilator version is 4.110 ...

@agrobman agrobman added the new New issue not seen by maintainers label Sep 13, 2021
@agrobman
Copy link
Author

BTW, why doesn't the verilator executable stop without $finish in the initial statement of the example? ( all verilog simulators do stop without $finish for this code)

Sorry - our verilator version is 4.200:
Verilator 4.200 2021-03-12 rev v4.110-43-g5022e81af (mod)

@wsnyder wsnyder changed the title plusarg is not picked up from command line Fix empty if removes function with side effect Sep 13, 2021
@wsnyder
Copy link
Member

wsnyder commented Sep 13, 2021

The empty if body triggers the statement's removal which is incorrect because the condition has a side effect. Will need to detect and avoid its removal.

@wsnyder wsnyder added area: runtime result resolution: fixed Closed; fixed and removed new New issue not seen by maintainers labels Sep 13, 2021
@wsnyder
Copy link
Member

wsnyder commented Sep 13, 2021

Fixed. Note there are likely other cases where side effects are still erroneously removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: wrong runtime result Issue involves an incorrect runtine result from Verilated model resolution: fixed Closed; fixed
Projects
None yet
Development

No branches or pull requests

2 participants