#878 Assertion fail with no-args function

Cary R.
Other (110)

Icarus Verilog version: 0.9.4
Platform: Ubuntu Linux 11.10 (xubuntu)
Build command line: iverilog -o tb_DiscReader main.v

When attempting to compile the attached file, the 'fifo_read' function causes an internal assertion failure:

|| iverilog -o tb_DiscReader main.v
main.v|74| syntax error
ivl: ./parse.y|2398| int VLparse(): Assertion `current_function == 0' failed.
|| Aborted

The function in question is:

function fifo\_read\(\);
        fifo\_count = fifo\_count - 1;
        fifo\_rdptr = fifo\_rdptr + 1;
        fifo\_read = fifo\_buffer\[fifo\_rdptr\];

Line 74 is the 'begin' line (second line of the function).
Adding an input or output statement between the 'function' and 'begin' lines works around the issue, but makes it impossible to have a function which operates only on global state.


  • Philip Pemberton

    Test code which causes the failure

  • Cary R.

    Cary R. - 2012-01-09
    • assigned_to: nobody --> caryr
    • labels: --> Other
    • status: open --> open-invalid
  • Cary R.

    Cary R. - 2012-01-09

    Verilog (1364-2005) does not support a function without arguments. From the standard "A function shall have at least one input declared." In SystemVerilog (1800-2005 and later) this is allowed and the development version of Icarus does support this when the SV flag is used. Icarus only has limited SV support so it is not enabled by default.

    I'm going to mark this report invalid, but it would be best if V0.9 generated a better message so I'm going to leave it open until I have time to add a better message to the V0.9 branch. This should be possible since development catches this without asserting.

  • Philip Pemberton

    That's fair enough -- though surprisingly my reference books don't mention this. I can hardly argue with the standard though :)

    But I do agree with you on the second point -- the error message isn't exactly clear. Assert fail suggests the compiler died horribly. Something like "functions must have at least one input or output argument, unless in SystemVerilog mode" would be appreciated.


  • Cary R.

    Cary R. - 2012-01-09

    You can argue with the standard, but you won't get very far.

    Since V0.9 doesn't support SV this will be a this is not supported error and yes, an assert is a fatal compiler problem which should not happen from user generated code. FYI a function must have at least one input, an output in the argument list is not enough.

  • Cary R.

    Cary R. - 2012-01-10
    • status: open-invalid --> closed-invalid
  • Cary R.

    Cary R. - 2012-01-10

    I've push a patch that fixes the assert. It also adds better messages when calling a function with no arguments, but it's not trivial to add this to the function definition so it will just print a syntax error message. Hopefully the combination of the syntax error and the descriptive error when calling will make this clear enough. This is fully handled in development.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks