aboutsummaryrefslogtreecommitdiffstats
path: root/bugs/yosys_11.md
blob: 341155c08786b8a64241b8c13b00caa8de7c1e7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Constant 1 when indexing for loop variable

[ Fixed by [`4b18a45`](https://github.com/YosysHQ/yosys/commit/4b18a4528ba7597bd7437837ab6d34cd8de2e110) | Not reported ]

## Affected versions

- Yosys 0.9

## Description

In the following Verilog code, the third bit in `reg1` should never be 1, because it will always be less than 2.

```verilog
module top(y, clk);
  output y;
  input clk;
  reg [5:0] reg1 = 0;
  reg signed [8:0] reg2 = 0;
  assign y = reg2;
  always @(posedge clk)
    for (reg1 = 0; reg1 < 2; reg1 = reg1 + 1)
      reg2 <= reg1[2:2];
endmodule
```

However, in Yosys 0.9 it is compiled to the following, which outputs a constant one after the first clock cycle:

```verilog
/* Generated by Yosys 0.9 (git sha1 1979e0b1, clang 7.0.1-8 -fPIC -Os) */

module top(y, clk);
  input clk;
  wire [5:0] reg1;
  wire [8:0] reg2;
  output y;
  reg \reg2_reg[0]  = 1'h0;
  always @(posedge clk)
      \reg2_reg[0]  <= 1'h1;
  assign reg2[0] = \reg2_reg[0] ;
  assign reg1 = 6'h00;
  assign reg2[8:1] = 8'h00;
  assign y = reg2[0];
endmodule
```

The expected output is generated by the current master version of Yosys:

```verilog
/* Generated by Yosys 0.9+932 (git sha1 4b18a452, clang 7.0.1-8 -fPIC -Os) */

module top(y, clk);
  input clk;
  wire [5:0] reg1;
  wire [8:0] reg2;
  output y;
  assign reg1 = 6'h00;
  assign reg2 = 9'h000;
  assign y = 1'h0;
endmodule
```