Dead Code Linting Rule


Dead code is code that does not have any effect on your simulation or synthesis. Examples of dead code are signals that are never used or conditions that are never triggered.

Dead code does not bother the simulator or the synthesis tool. However, it consumes mental energy of anybody reading the code. People will try to figure out the purpose of a given statement and it may take a while before they realize that they are dealing with dead code. This makes it more expensive to review code and reuse code. In general, dead code is a form of technical debt that should be avoided.

Sigasi Studio flags some kinds of dead code:

  • Unused declarations (signals, constants …):

    architecture RTL of empty is
        signal   unused_s : bit;
        constant unused_c : bit := '0';
    begin end;
    

    A Quick Fix is available to help you remove unused declarations fast.

  • Unused ports and generics:

    entity empty is
        generic(unused_g : bit);
        port   (unused_p : in bit);
    end entity;
    
    architecture RTL of empty is begin end;
    
  • Unreachable statements: if the Sigasi Studio analyzer can determine that a condition is always false, it will mark the if-statement because it contains dead code:

    if true then
        v := v + 1;
    else
        v := v - 1;
    end if;
    
  • Dead states in a state machine: a state is considered dead if it has no outgoing transitions:

    type t_state is (IDLE, START, RUN, DONE);
    signal state: t_state;
      -- [omitted code]
      case state is
        when IDLE   => -- do something
            state <= RUN;
        when RUN    => -- do something
            state <= DONE;
        when DONE   => -- do something
            state <= IDLE;
        when others => -- do nothing
      end case;
    

Rule configuration

These rules can be disabled for your project, or their severity and parameters can be modified in the project linting settings. Alternatively, they can be manually configured with the following template:

55/severity/${path}={error|warning|info|ignore} # Unused declaration
67/severity/${path}={error|warning|info|ignore} # Unused ports
68/severity/${path}={error|warning|info|ignore} # Unused generics
85/severity/${path}={error|warning|info|ignore} # Unreachable statements
71/severity/${path}={error|warning|info|ignore} # Dead states