From 19abcb04ad005a21319354550e87bfd428ec5597 Mon Sep 17 00:00:00 2001 From: Jim Lawson Date: Wed, 20 Dec 2017 16:16:13 -0800 Subject: Verify shl/shr amount is > 0 (#710) Fixes #527 --- src/test/scala/firrtlTests/CheckSpec.scala | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/scala/firrtlTests/CheckSpec.scala b/src/test/scala/firrtlTests/CheckSpec.scala index 0d0df020..50a28f80 100644 --- a/src/test/scala/firrtlTests/CheckSpec.scala +++ b/src/test/scala/firrtlTests/CheckSpec.scala @@ -7,7 +7,7 @@ import org.scalatest._ import org.scalatest.prop._ import firrtl.Parser import firrtl.ir.Circuit -import firrtl.passes.{Pass,ToWorkingIR,CheckHighForm,ResolveKinds,InferTypes,CheckTypes,PassExceptions,InferWidths,CheckWidths,ResolveGenders,CheckGenders} +import firrtl.passes.{Pass,ToWorkingIR,CheckHighForm,ResolveKinds,InferTypes,CheckTypes,PassException,InferWidths,CheckWidths,ResolveGenders,CheckGenders} class CheckSpec extends FlatSpec with Matchers { "Connecting bundles of different types" should "throw an exception" in { @@ -242,4 +242,25 @@ class CheckSpec extends FlatSpec with Matchers { } } + for (op <- List("shl", "shr")) { + s"$op by negative amount" should "result in an error" in { + val passes = Seq( + ToWorkingIR, + CheckHighForm + ) + val amount = -1 + val input = + s"""circuit Unit : + | module Unit : + | input x: UInt<3> + | output z: UInt + | z <= $op(x, $amount)""".stripMargin + val exception = intercept[PassException] { + passes.foldLeft(Parser.parse(input.split("\n").toIterator)) { + (c: Circuit, p: Pass) => p.run(c) + } + } + exception.getMessage should include (s"Primop $op argument $amount < 0") + } + } } -- cgit v1.2.3