Skip to content

Commit

Permalink
OpMap: Fix StateMachine issue.
Browse files Browse the repository at this point in the history
When we are in the CoreOp or Intrinsic state and are about to transition
to the DialectOp state, then we cannot just access the
DialectOpIteratorT in the internal variant storage, since the new
iterator (m_dialectOps.begin()) is not stored in the variant yet.
  • Loading branch information
Thomas Symalla committed Oct 12, 2023
1 parent e7efb52 commit df9fdd9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/llvm-dialects/Dialect/OpMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,13 @@ template <typename ValueT, bool isConst> class OpMapIteratorBase final {
}

if (nextState == IteratorState::DialectOp) {
// If we are about to transition to a new state, we cannot assume that
// the call to std::get will succeed.
if (currentState != nextState)
return !m_iterator.m_map->m_dialectOps.empty()
? IteratorState::DialectOp
: IteratorState::Invalid;

auto peek = std::get<DialectOpIteratorT>(m_iterator.m_iterator);
std::advance(peek, 1);
if (peek != m_iterator.m_map->m_dialectOps.end())
Expand Down

0 comments on commit df9fdd9

Please sign in to comment.