Skip to content

Commit 2905a48

Browse files
committed
Fix DfaEmitter::visitDfaState() crash in MSVC x86 debug builds (PR44945)
No functionality change (intended), but this seems to make the code a bit clearer for the compiler and maybe for human readers too. (cherry picked from commit edae4be)
1 parent bbfdf4b commit 2905a48

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

llvm/utils/TableGen/DFAEmitter.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ void DfaEmitter::addTransition(state_type From, state_type To, action_type A) {
5353
++NumNfaTransitions;
5454
}
5555

56-
void DfaEmitter::visitDfaState(DfaState DS) {
56+
void DfaEmitter::visitDfaState(const DfaState &DS) {
5757
// For every possible action...
5858
auto FromId = DfaStates.idFor(DS);
5959
for (action_type A : Actions) {
6060
DfaState NewStates;
6161
DfaTransitionInfo TI;
6262
// For every represented state, word pair in the original NFA...
63-
for (state_type &FromState : DS) {
63+
for (state_type FromState : DS) {
6464
// If this action is possible from this state add the transitioned-to
6565
// states to NewStates.
6666
auto I = NfaTransitions.find({FromState, A});
@@ -90,8 +90,11 @@ void DfaEmitter::constructDfa() {
9090

9191
// Note that UniqueVector starts indices at 1, not zero.
9292
unsigned DfaStateId = 1;
93-
while (DfaStateId <= DfaStates.size())
94-
visitDfaState(DfaStates[DfaStateId++]);
93+
while (DfaStateId <= DfaStates.size()) {
94+
DfaState S = DfaStates[DfaStateId];
95+
visitDfaState(S);
96+
DfaStateId++;
97+
}
9598
}
9699

97100
void DfaEmitter::emit(StringRef Name, raw_ostream &OS) {

llvm/utils/TableGen/DFAEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class DfaEmitter {
9999
void constructDfa();
100100
/// Visit a single DFA state and construct all possible transitions to new DFA
101101
/// states.
102-
void visitDfaState(DfaState DS);
102+
void visitDfaState(const DfaState &DS);
103103
};
104104

105105
} // namespace llvm

0 commit comments

Comments
 (0)