verilator/test_regress/t/t_lint_width_bad.v

51 lines
1.4 KiB
Systemverilog
Raw Normal View History

// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain.
// SPDX-FileCopyrightText: 2009 Wilson Snyder
// SPDX-License-Identifier: CC0-1.0
2026-03-03 13:21:24 +01:00
module t;
2026-03-10 02:38:29 +01:00
// See also t_math_width
2014-05-11 03:51:21 +02:00
2026-03-10 02:38:29 +01:00
// This shows the uglyness in width warnings across param modules
// TODO: Would be nice to also show relevant parameter settings
p #(.WIDTH(4)) p4 (.in(4'd0));
p #(.WIDTH(5)) p5 (.in(5'd0));
2026-03-10 02:38:29 +01:00
//====
localparam [3:0] XS = 'hx; // User presumably intended to use 'x
2014-05-11 03:51:21 +02:00
2026-03-10 02:38:29 +01:00
//====
wire [4:0] c = 1'b1 << 2; // No width warning, as is common syntax
wire [4:0] d = (1'b1 << 2) + 5'b1; // Has warning as not obvious what expression width is
2014-05-11 03:51:21 +02:00
2026-03-10 02:38:29 +01:00
//====
localparam WIDTH = 6;
wire one_bit;
wire [2:0] shifter = 1;
wire [WIDTH-1:0] masked = (({{(WIDTH) {1'b0}}, one_bit}) << shifter);
2014-05-11 03:51:21 +02:00
2026-03-10 02:38:29 +01:00
//====
// We presently warn here, in theory we could detect if the number of one bit additions could overflow the LHS
wire one = 1;
wire [2:0] cnt = (one + one + one + one);
2014-05-11 03:51:21 +02:00
2026-03-10 02:38:29 +01:00
// Not harmless > or >= compared with something wider (as different results if "a" wider)
localparam [40:0] THREE = 3;
int a;
initial for (a = 0; a > THREE; ++a) $display(a);
initial for (a = 0; a >= THREE; ++a) $display(a);
2026-03-10 02:38:29 +01:00
initial if (THREE) $stop;
2020-10-22 23:13:42 +02:00
endmodule
2026-03-10 02:38:29 +01:00
module p #(
parameter WIDTH = 64
) (
input [WIDTH-1:0] in
);
wire [4:0] out = in;
endmodule