Skip to content

thread 'main' has overflowed its stack #97

Open

Description

@mlr11

The piece of verilog code below is causing the parser to exit with:

thread 'main' has overflowed its stack.

I tried increasing the stack up to 64M without any luck.

The somewhat convoluted expression is giving a tough time to the parser.

module test (
    input wire clk,
    input wire reset,
    input wire lcomreq,
    input wire lmask1,
    input wire lmask0,
    input wire req3,
    input wire req2,
    input wire req1,
    input wire req0,
    output reg lgnt0
);

always @(posedge clk or posedge reset) begin
    if (reset) begin
        lgnt0 <= 1'b0;
    end else begin
        lgnt0 <= (~lcomreq & ~lmask1 & ~lmask0 & ~req3 & ~req2 & ~req1 & req0)
               | (~lcomreq & ~lmask1 &  lmask0 & ~req3 & ~req2 &  req0)
               | (~lcomreq &  lmask1 & ~lmask0 & ~req3 &  req0)
               | (~lcomreq &  lmask1 &  lmask0 & req0  )
               | ( lcomreq & lgnt0 );
    end
end

endmodule

Everything works as expected if I refactor the code and create intermediate terms for each part of the 'or'
The always block would look like:

always @(posedge clk or posedge reset) begin
    if (reset) begin
        lgnt0 <= 1'b0;
    end else begin
        lgnt0 <= term1 | term2 | term3 | term4 | term5;
    end
end

with wire assignment for each of the terms.

Activity

  1. mlr11 commented on May 27, 2024

    @mlr11
    Author

    sv_parser might not be the culprit here. I kept getting this error for the majority of the verilog designs I was trying to use.
    Even some of the passing examples from the sv-test suite were failing with the same message.

    I tried switching from Windows to Linux (WSL - Ubuntu 22.04) and all of my problems went away.

  2. yousifBilal commented on Aug 14, 2024

    @yousifBilal

    I also ran into stack overflows on some designs

  3. henry-hsieh commented on Jan 27, 2026

    @henry-hsieh

    The problem is that expression may recursively call itself due to the SystemVerilog LRM. Therefore, the used stack size will be constantly increased when the source code uses nested expressions such as a lot of binary operations in a statement. The solution is replacing the expression with iteration-based implementation. However, it may change the look of the LRM.

    expression ::=
        primary
      | unary_operator { attribute_instance } primary
      | inc_or_dec_expression
      | ( operator_assignment )
      | expression binary_operator { attribute_instance } expression
      | conditional_expression
      | inside_expression
      | tagged_union_expression
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions