diff --git a/lib/Conversion/HandshakeToFIRRTL/HandshakeToFIRRTL.cpp b/lib/Conversion/HandshakeToFIRRTL/HandshakeToFIRRTL.cpp index 29931cda1669..6f79d5817d0d 100644 --- a/lib/Conversion/HandshakeToFIRRTL/HandshakeToFIRRTL.cpp +++ b/lib/Conversion/HandshakeToFIRRTL/HandshakeToFIRRTL.cpp @@ -2144,6 +2144,9 @@ static void createInstOp(Operation *oldOp, FModuleOp subModuleOp, [](BlockArgument &arg) -> bool { return arg.getType().isa(); }); + assert(firstClock != topArgs.end() && "Expected a clock signal"); + unsigned firstClkIdx = std::distance(topArgs.begin(), firstClock); + if (portIndex < numIns) { // Connect input ports. rewriter.create(oldOp->getLoc(), result, @@ -2153,8 +2156,11 @@ static void createInstOp(Operation *oldOp, FModuleOp subModuleOp, Value newResult = oldOp->getResult(portIndex - numIns); newResult.replaceAllUsesWith(result); } else { - // Connect clock or reset signal. - auto signal = *(firstClock + 2 * clockDomain + portIndex - numArgs); + // Connect clock or reset signal(s). + unsigned clkOrResetIdx = + firstClkIdx + 2 * clockDomain + portIndex - numArgs; + assert(topArgs.size() > clkOrResetIdx); + auto signal = topArgs[clkOrResetIdx]; rewriter.create(oldOp->getLoc(), result, signal); } ++portIndex;