Skip to content

Commit

Permalink
Save/restore when+layer stack w/D/I, fix crashes. (#4442)
Browse files Browse the repository at this point in the history
Add tests that demonstrate crashing without this change.

Fixes #4441.
  • Loading branch information
dtzSiFive authored Oct 4, 2024
1 parent d9e4741 commit 55bd8ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/scala/chisel3/ModuleImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,12 @@ private[chisel3] trait ObjectModuleImpl {
implicit sourceInfo: SourceInfo
): T = {
val parent = Builder.currentModule
val whenStackOpt = Option.when(Builder.hasDynamicContext)(Builder.whenStack)
val layerStackOpt = Option.when(Builder.hasDynamicContext)(Builder.layerStack)
val module: T = bc // bc is actually evaluated here
if (!parent.isEmpty) { Builder.currentModule = parent }
whenStackOpt.foreach(Builder.whenStack = _)
layerStackOpt.foreach(Builder.layerStack = _)

module
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ class InstanceSpec extends ChiselFunSpec with Utils {
val chirrtl = circt.stage.ChiselStage.emitCHIRRTL(new Top)
chirrtl should include("connect i0.realIn.aminusx, UInt<7>(0h7b)")
}
it("(0.f): access under when does not crash") {
class Top extends Module {
val definition = Definition(new AddTwo)
val i0 = Instance(definition)
when(true.B) {
val i = i0.i0 // This should not error
}
}
circt.stage.ChiselStage.emitCHIRRTL(new Top)
}
it("(0.g): access under layer does not crash") {
object A extends layer.Layer(layer.LayerConfig.Extract())
class Top extends Module {
val definition = Definition(new AddTwo)
val i0 = Instance(definition)
layer.block(A) {
val i = i0.i0 // This should not error
}
layer.block(A) {
val i = i0.i1 // This should not error
}
}
circt.stage.ChiselStage.emitCHIRRTL(new Top)
}
}
describe("(1) Annotations on instances in same chisel compilation") {
it("(1.a): should work on a single instance, annotating the instance") {
Expand Down

0 comments on commit 55bd8ac

Please sign in to comment.