Project

General

Profile

[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  BugVise
  CovVise
  Force-Gate-Sim
  Gspice
  IPC::Locker
  Rsvn
  SVN::S4
  Voneline
  WFH
General Info
  Papers

Issue #1442

Enum value not made sized when enum sized

Added by Dan Petrisko 4 months ago. Updated 22 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Lint
% Done:

0%


Description

typedef enum logic[2:0] {P=0, W, E, N, S} Dirs;

module test;

  localparam LEN = 3;
  localparam COL = 4;
  localparam [59:0] SEQ = {LEN'(N), LEN'(E), LEN'(W), LEN'(P)
                   ,LEN'(S), LEN'(E), LEN'(W), LEN'(P)
                   ,LEN'(S), LEN'(N), LEN'(W), LEN'(P)
                   ,LEN'(S), LEN'(N), LEN'(E), LEN'(P)
                   ,LEN'(S), LEN'(N), LEN'(E), LEN'(W)};

endmodule
$ verilator --lint-only test.v 
%Warning-WIDTHCONCAT: test.v:8: Unsized numbers/parameters not allowed in concatenations.
%Warning-WIDTHCONCAT: Use "/* verilator lint_off WIDTHCONCAT */" and lint_on around source to disable this message.
%Warning-WIDTHCONCAT: test.v:9: Unsized numbers/parameters not allowed in concatenations.
%Warning-WIDTHCONCAT: test.v:10: Unsized numbers/parameters not allowed in concatenations.
%Warning-WIDTHCONCAT: test.v:11: Unsized numbers/parameters not allowed in concatenations.
%Warning-WIDTHCONCAT: test.v:12: Unsized numbers/parameters not allowed in concatenations.
%Warning-WIDTHCONCAT: test.v:8: Unsized numbers/parameters not allowed in replications.
%Error: Exiting due to 6 warning(s)
%Error: Command Failed /usr/bin/verilator_bin --lint-only test.v

The fix is to explictly size the enum value. But it seems like the typedef should take care of this
typedef enum logic[2:0] {P=3'd0, W, E, N, S} Dirs;

History

#1 Updated by Dan Petrisko 4 months ago

$ verilator --lint-only test.v

%Warning-WIDTHCONCAT: test.v:8:

Unsized numbers/parameters not allowed in concatenations.

%Warning-WIDTHCONCAT: Use "/* verilator lint_off WIDTHCONCAT */" and lint_on around source to disable this message.

%Warning-WIDTHCONCAT: test.v:9: Unsized numbers/parameters not allowed in concatenations.

%Warning-WIDTHCONCAT: test.v:10: Unsized numbers/parameters not allowed in concatenations.

%Warning-WIDTHCONCAT: test.v:11: Unsized numbers/parameters not allowed in concatenations.

%Warning-WIDTHCONCAT: test.v:12: Unsized numbers/parameters not allowed in concatenations.

%Warning-WIDTHCONCAT: test.v:8: Unsized numbers/parameters not allowed in replications.

%Error: Exiting due to 6 warning(s) %Error: Command Failed /usr/bin/verilator_bin --lint-only test.v

The fix is to explictly size the enum value. But it seems like the typedef should take care of this

typedef enum logic[2:0] {P=3'd0, W, E, N, S} Dirs;

#2 Updated by Dan Petrisko 4 months ago

Verilator 4.015 devel rev UNKNOWN_REV

#3 Updated by Wilson Snyder 4 months ago

  • Subject changed from Enum values without explicit widths are considered unsized to Enum value not truncated to enum size
  • Description updated (diff)
  • Category set to Lint
  • Status changed from New to Confirmed
  • Assignee set to Wilson Snyder

I suspect you added the LEN casts to try to work around this, but note they are unnecessary to show the problem, which can simply be seen with

typedef enum logic [2:0] {P=0};
localparam [5:0] SEQ = {P, P};

What is happening is the assignment of P to 0 is seen as unsized because the zero is unsized. Indeed if you use P=3'b0 it works. This is an unfortunate side effect of trying not to give WIDTH warnings when a user does "enum { P=0 }" then uses P in a context that is looking for only a few bit wide number (versus 32 bits wide).

Requires some experiments as how to fix this without adding those unfortunate WIDTH warnings.

#4 Updated by Wilson Snyder 4 months ago

  • Subject changed from Enum value not truncated to enum size to Enum value not made sized when enum sized

#5 Updated by Wilson Snyder 3 months ago

  • Status changed from Confirmed to Resolved

Fixed in git towards 4.018.

I tried a few alternatives to preserve the behavior I thought was best for WIDTH warnings but ended up not finding anything that seemed consistent and didn't break this case (which seemed worse).

#6 Updated by Wilson Snyder 22 days ago

  • Status changed from Resolved to Closed

In 4.018.

Also available in: Atom