Skip to content

SV: non-ANSI port and net ranges are compared as text, rejecting equal ranges (blocks rtlmeter E902/E906) #2126

Closed

Description

@tignear

Non-ANSI port and net ranges are compared as text, so equal ranges are rejected

The SV parser rejects a non-ANSI port whose net or variable declaration spells the same range differently. This blocks rtlmeter XuanTie-E902 and E906 at compile time.

The construct in E902 (cr_clic_busif, from openE902's generated RTL)

`define EXT_INT_NUM          64
`define CLIC_INTNUM   `EXT_INT_NUM+16          // 80
...
module cr_clic_busif( ... busif_kid_clicintattr_sel, ... );
parameter CLICINTNUM = `CLIC_INTNUM;
...
output  [79  :0]  busif_kid_clicintattr_sel;
...
wire [CLICINTNUM-1:0] busif_kid_clicintattr_sel;   // [79:0]

Four outputs have this shape (busif_kid_clicint{attr,ctl,ie,ip}_sel). The two ranges are both [79:0] once evaluated.

What the LRM says

IEEE 1800-2023 23.2.2.1 (Non-ANSI style port declarations): "If a port declaration does not include a net or variable type, then the port can be again declared in a net or variable declaration. If the net or variable is declared as a vector, the range specification between the two declarations of a port shall be identical."

The ranges here specify the same bounds. The check added with non-ANSI ports (#1954) compares the token text of the dimensions instead (crates/celox-sv-syntax/src/parser/non_ansi.rs, merge_port_type), so [79:0] and [CLICINTNUM-1:0] differ.

Minimal repro and other simulators

`define EXT_INT_NUM 64
`define CLIC_INTNUM `EXT_INT_NUM+16
module child(o);
parameter N = `CLIC_INTNUM;
output [79:0] o;
wire [N-1:0] o;
assign o = {N{1'b1}};
endmodule
module top;
wire [79:0] o;
child c(o);
initial #1 $display("%h", o);
endmodule
case Celox (master) Verilator 5.052 Icarus 13.0
a: the repro (N = 64+16 from a macro) error prints ffffffffffffffffffff prints ffffffffffffffffffff
b: parameter N = 80; error ok ok
c: real mismatch, parameter N = 64; ([79:0] vs [63:0]) error error ("Non-ANSI I/O declaration of signal conflicts with type declaration") error ("Vectored port o [79:0] has a net declaration [63:0] ... that does not match")
d: both written [N-1:0] ok ok ok

All three tools agree that a real mismatch (c) is an error. Only Celox rejects equal ranges written differently (a, b).

Proposal

  1. Fix (needed for E902/E906): compare the evaluated bounds, after parameters and macros are resolved, in elaboration rather than on the parser's tokens. Equal bounds are accepted, as the LRM, Verilator and Icarus do.

  2. For a real mismatch like case (c), there are two options:

    • keep it a hard error, as today and as Verilator and Icarus do; or
    • make it a diagnostic that can be relaxed: an error by default, or a warning by default, with --diagnostic to change it, where the port declaration's range wins.

    The default is yours to decide. My recommendation is to keep the error by default, since every reference tool rejects it, and add the relaxable diagnostic only if a design needs it. E902/E906 need only fix 1.

Found while widening the designs used to measure #2013's partitioning heuristic.

Activity

  1. tignear commented on Oct 26, 2026

    @tignear
    ContributorAuthor

    Decision (maintainer): equal ranges written differently must be accepted (compare evaluated bounds). A real mismatch stays an error, per 23.2.2.1, as in Verilator and Icarus.

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