8000 Fix to lint error on queue compared to int · Issue #5570 · verilator/verilator · GitHub
[go: up one dir, main page]

Skip to content

Fix to lint error on queue compared to int #5570

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

Closed
hankhsu1996 opened this issue Oct 28, 2024 & 8000 middot; 2 comments · Fixed by #5950
Closed

Fix to lint error on queue compared to int #5570

hankhsu1996 opened this issue Oct 28, 2024 · 2 comments · Fixed by #5950
Labels
area: lint Issue involves SystemVerilog lint checking resolution: fixed Closed; fixed

Comments

@hankhsu1996
Copy link
Contributor

Issue Description:
Verilator throws a compilation error when calling a function with a cross-module reference that includes a $fatal statement. The error only occurs when $fatal is present; otherwise, the code compiles without issues.

Example Code:

module DUT;
  function automatic int find_elem(int elem, int array[]);
    int index;

    index = array.find_first_index(x) with (x == elem);
    if (index == -1) begin
      $fatal(1, "Element not found in array");
    end

    return index;
  endfunction
endmodule

module Testbench;
  DUT dut();

  initial begin
    int array[] = '{5, 4, 3, 2, 1};
    int index = dut.find_elem(2, array);
  end
endmodule

Verilator Command:

verilator test.sv --cc --exe --binary --main

Error Message:

In file included from Vtest__ALL.cpp:8:
Vtest___024root__DepSet_h9b2d61ff__0__Slow.cpp: In function ‘void Vtest___024root___eval_initial__TOP(Vtest___024root*)’:
Vtest___024root__DepSet_h9b2d61ff__0__Slow.cpp:31:81: error: cannot convert ‘VlQueue<unsigned int>’ to ‘IData’ {aka ‘unsigned int’} in assignment
   31 |         = __Vfunc_Testbench__DOT__dut__DOT__find_elem__0__array.find_first_index(
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
      |                                                                                 |
      |                                                                                 VlQueue<unsigned int>
   32 |                                                                                 [&](
      |                                                                                 ~~~~
   33 |                                                                                 IData/*31:0*/ x__DOT__index,
      |                                                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   34 |                                                                                 IData/*31:0*/ x) {
      |                                                                                 ~~~~~~~~~~~~~~~~~~
   35 |             return ((2U == x));
      |             ~~~~~~~~~~~~~~~~~~~                                                  
   36 |         }
      |         ~                                                                        
   37 |     );
      |     ~ 

Verilator Version:
Verilator 5.031 (devel) rev v5.030-1-g68e0cf552 (git master)

OS and Distribution:
WSL Ubuntu 22.04.4

Additional Notes:

  • The error only occurs when the function is called across modules.
  • Removing $fatal eliminates the issue.
@hankhsu1996 hankhsu1996 added the new New issue not seen by maintainers label Oct 28, 2024
@wsnyder wsnyder added area: lint Issue involves SystemVerilog lint checking status: ready Issue is ready for someone to fix; then goes to 'status: assigned' and removed new New issue not seen by maintainers labels Oct 29, 2024
@wsnyder wsnyder changed the title Compile error with with clause in cross-module function call Fix to lint error on queue compared to int Oct 29, 2024
@wsnyder
Copy link
Member
wsnyder commented Oct 29, 2024

This code is illegal. Verilator needs to add an error you are comparing a queue with an int.

If the $fatal is removed, the if gets optimized away so you don't get the compile error (but should still get the new lint error proposed.)

@hankhsu1996
Copy link
Contributor Author

Thank you -- I didn't notice the return type of find_first_index is still a queue.

@wsnyder wsnyder added resolution: fixed Closed; fixed and removed status: ready Issue is ready for someone to fix; then goes to 'status: assigned' labels May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: lint Issue involves SystemVerilog lint checking resolution: fixed Closed; fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0