Skip to content

Commit ee6b214

Browse files
Add a test for issue 4159 (#4161) (#4164)
Co-authored-by: Schuyler Eldridge <schuyler.eldridge@sifive.com> (cherry picked from commit 15115ea) Co-authored-by: Jack Koenig <koenig@sifive.com>
1 parent a5e445c commit ee6b214

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/test/scala/chiselTests/ChiselEnum.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,30 @@ class ChiselEnumSpec extends ChiselFlatSpec with Utils {
402402
assertTesterPasses(new CastToUIntTester)
403403
}
404404

405+
// This is a bug, but fixing it may break user code.
406+
// See: https://github.com/chipsalliance/chisel/issues/4159
407+
it should "preserve legacy width behavior" in {
408+
val verilog = ChiselStage.emitSystemVerilog(new RawModule {
409+
val out1, out2, out3 = IO(Output(UInt(8.W)))
410+
val e = EnumExample.e1
411+
val x = e.asUInt
412+
val y = e.asTypeOf(UInt())
413+
val z = e.asTypeOf(UInt(e.getWidth.W))
414+
out1 := Cat(1.U, x)
415+
out2 := Cat(1.U, y)
416+
out3 := Cat(1.U, z)
417+
// The bug is that the width of x is 7 but the value of out1 is 3
418+
x.getWidth should be(7)
419+
x.getWidth should be(EnumExample.getWidth)
420+
y.widthOption should be(None)
421+
z.getWidth should be(7)
422+
})
423+
// The bug is that all of these should be the same as out3, or the widths above are wrong
424+
verilog should include("assign out1 = 8'h3;")
425+
verilog should include("assign out2 = 8'h3;")
426+
verilog should include("assign out3 = 8'h81;")
427+
}
428+
405429
it should "cast literal UInts to enums correctly" in {
406430
assertTesterPasses(new CastFromLitTester)
407431
}

0 commit comments

Comments
 (0)