Skip to content

Commit

Permalink
[NFC][HandshakeToFIRRLT] Add asserts to dangerous iterator arithmetic
Browse files Browse the repository at this point in the history
Spent a good amount of time fighting with a memory corruption error which resulted from this site... asserts added to avoid future time waste!
  • Loading branch information
mortbopet committed Nov 1, 2021
1 parent 558dc90 commit 1ec2489
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/Conversion/HandshakeToFIRRTL/HandshakeToFIRRTL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,9 @@ static void createInstOp(Operation *oldOp, FModuleOp subModuleOp,
[](BlockArgument &arg) -> bool {
return arg.getType().isa<ClockType>();
});
assert(firstClock != topArgs.end() && "Expected a clock signal");
unsigned firstClkIdx = std::distance(topArgs.begin(), firstClock);

if (portIndex < numIns) {
// Connect input ports.
rewriter.create<ConnectOp>(oldOp->getLoc(), result,
Expand All @@ -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<ConnectOp>(oldOp->getLoc(), result, signal);
}
++portIndex;
Expand Down

0 comments on commit 1ec2489

Please sign in to comment.