diff --git a/src/main/scala/chisel3/aop/Select.scala b/src/main/scala/chisel3/aop/Select.scala index 4babe518597..09f5535c20d 100644 --- a/src/main/scala/chisel3/aop/Select.scala +++ b/src/main/scala/chisel3/aop/Select.scala @@ -370,6 +370,7 @@ object Select { */ def attachedTo(module: BaseModule)(signal: Data): Set[Data] = { check(module) +<<<<<<< HEAD module._component.get .asInstanceOf[DefModule] .commands @@ -378,6 +379,16 @@ object Select { } .flatMap { seq => seq.map(_.id.asInstanceOf[Data]) } .toSet +======= + collect( + module._component.get + .asInstanceOf[DefModule] + .block + .getCommands() + ) { + case Attach(_, seq) if seq.contains(Node(signal)) => seq + }.flatMap { seq => seq.map(_.id.asInstanceOf[Data]) }.toSet +>>>>>>> 1aa41cdb7 (Fix Select.attachedTo (#4458)) } /** Selects all connections to a signal or its parent signal(s) (if the signal is an element of an aggregate signal) diff --git a/src/test/scala/chiselTests/aop/SelectSpec.scala b/src/test/scala/chiselTests/aop/SelectSpec.scala index 87df42844f8..60d83cacdc2 100644 --- a/src/test/scala/chiselTests/aop/SelectSpec.scala +++ b/src/test/scala/chiselTests/aop/SelectSpec.scala @@ -130,6 +130,20 @@ class SelectSpec extends ChiselFlatSpec { ) } + "Test" should "pass if selecting attach" in { + import chisel3.experimental.{attach, Analog} + class AttachTest extends RawModule { + val a, b, c = IO(Analog(8.W)) + attach(a, b, c) + } + val dut = ChiselGeneratorAnnotation(() => new AttachTest) + .elaborate(1) + .asInstanceOf[DesignAnnotation[AttachTest]] + .design + Select.attachedTo(dut)(dut.a) should be(Set(dut.a, dut.b, dut.c)) + + } + "Test" should "pass if selecting ops by kind" in { execute( () => new SelectTester(Seq(0, 1, 2)),