Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative Width Gives Bad Error Message #4007

Closed
seldridge opened this issue Apr 17, 2024 · 0 comments · Fixed by #4008
Closed

Negative Width Gives Bad Error Message #4007

seldridge opened this issue Apr 17, 2024 · 0 comments · Fixed by #4008

Comments

@seldridge
Copy link
Member

If you have a negative width, this produces a bad error message about "requirement failed". Consider:

//> using scala "2.13.12"
//> using repository sonatype-s01:snapshots
//> using lib "org.chipsalliance::chisel::6.0.0+74-0a437d8f-SNAPSHOT"
//> using plugin "org.chipsalliance:::chisel-plugin::6.0.0+74-0a437d8f-SNAPSHOT"
//> using options "-unchecked", "-deprecation", "-language:reflectiveCalls", "-feature", "-Xcheckinit", "-Xfatal-warnings", "-Ywarn-dead-code", "-Ywarn-unused", "-Ymacro-annotations"

import chisel3._
import circt.stage.ChiselStage

class Foo extends RawModule with Public {
  val x = IO(Input(UInt(-8.W)))
}

object Main extends App {
  println(
    ChiselStage.emitSystemVerilog(
      new Foo,
      firtoolOpts = Array("-g", "-emit-hgldd", "-output-final-mlir=Foo.mlir")
    )
  )
}

This produces:

Exception in thread "main" java.lang.IllegalArgumentException: requirement failed
	at ... ()
	at Foo.$anonfun$x$4(NegativeWidth.scala:11)
	at chisel3.SpecifiedDirection$.specifiedDirection(Data.scala:66)
	at chisel3.Input$.apply(Data.scala:264)
	at Foo.$anonfun$x$3(NegativeWidth.scala:11)
	at chisel3.IO$.apply(IO.scala:34)
	at chisel3.experimental.BaseModule.IO(Module.scala:821)
	at Foo.$anonfun$x$2(NegativeWidth.scala:11)
	at chisel3.experimental.prefix$.apply(prefix.scala:50)
	at Foo.$anonfun$x$1(NegativeWidth.scala:11)
	at chisel3.internal.plugin.package$.autoNameRecursively(package.scala:33)
	at Foo.<init>(NegativeWidth.scala:11)
	at Main$.$anonfun$new$1(NegativeWidth.scala:17)
	at ... ()
	at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)

h/t @mmaloney-sf for finding this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant