Skip to content

Commit

Permalink
Report Builder errors even when exception is thrown (#3341) (#3342)
Browse files Browse the repository at this point in the history
(cherry picked from commit b83f369)

Co-authored-by: Jack Koenig <koenig@sifive.com>
  • Loading branch information
mergify[bot] and jackkoenig authored Jun 8, 2023
1 parent 42b5a67 commit 46857a7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 15 additions & 4 deletions core/src/main/scala/chisel3/internal/Builder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import logger.LazyLogging
import scala.collection.mutable
import scala.annotation.tailrec
import java.io.File
import scala.util.control.NonFatal

private[chisel3] class Namespace(keywords: Set[String]) {
// This HashMap is compressed, not every name in the namespace is present here.
Expand Down Expand Up @@ -831,10 +832,20 @@ private[chisel3] object Builder extends LazyLogging {
ViewParent: Unit // Must initialize the singleton in a Builder context or weird things can happen
// in tiny designs/testcases that never access anything in chisel3.internal
logger.info("Elaborating design...")
val mod = f
if (forceModName) { // This avoids definition name index skipping with D/I
mod.forceName(mod.name, globalNamespace)
}
val mod =
try {
val m = f
if (forceModName) { // This avoids definition name index skipping with D/I
m.forceName(m.name, globalNamespace)
}
m
} catch {
case NonFatal(e) =>
// Make sure to report any aggregated errors in case the Exception is due to a tainted return value
// Note that errors.checkpoint may throw an Exception which will suppress e
errors.checkpoint(logger)
throw e
}
errors.checkpoint(logger)
logger.info("Done elaborating.")

Expand Down
14 changes: 14 additions & 0 deletions src/test/scala/circtTests/stage/ChiselStageSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,20 @@ class ChiselStageSpec extends AnyFunSpec with Matchers with chiselTests.Utils {
val version = chisel3.BuildInfo.firtoolVersion.getOrElse("<unknown>")
e.getMessage should include(s"firtool version $version")
}

it("should properly report Builder.errors even if there is a later Exception") {
val (log, _) = grabLog {
intercept[java.lang.Exception] {
import chisel3._
ChiselStage.emitCHIRRTL(new Module {
val in = IO(Input(UInt(8.W)))
val y = in >> -1
require(false) // This should not suppress reporting the negative shift
})
}
}
log should include("Negative shift amounts are illegal (got -1)")
}
}

describe("ChiselStage custom transform support") {
Expand Down

0 comments on commit 46857a7

Please sign in to comment.