Fix DfaEmitter::visitDfaState() crash in MSVC x86 debug builds (PR44945)
authorHans Wennborg <hans@chromium.org>
Tue, 25 Feb 2020 14:15:25 +0000 (15:15 +0100)
committerHans Wennborg <hans@chromium.org>
Tue, 25 Feb 2020 14:18:41 +0000 (15:18 +0100)
No functionality change (intended), but this seems to make the code a
bit clearer for the compiler and maybe for human readers too.

llvm/utils/TableGen/DFAEmitter.cpp
llvm/utils/TableGen/DFAEmitter.h

index 91c8638..7391f68 100644 (file)
@@ -53,14 +53,14 @@ void DfaEmitter::addTransition(state_type From, state_type To, action_type A) {
   ++NumNfaTransitions;
 }
 
-void DfaEmitter::visitDfaState(DfaState DS) {
+void DfaEmitter::visitDfaState(const DfaState &DS) {
   // For every possible action...
   auto FromId = DfaStates.idFor(DS);
   for (action_type A : Actions) {
     DfaState NewStates;
     DfaTransitionInfo TI;
     // For every represented state, word pair in the original NFA...
-    for (state_type &FromState : DS) {
+    for (state_type FromState : DS) {
       // If this action is possible from this state add the transitioned-to
       // states to NewStates.
       auto I = NfaTransitions.find({FromState, A});
@@ -90,8 +90,11 @@ void DfaEmitter::constructDfa() {
 
   // Note that UniqueVector starts indices at 1, not zero.
   unsigned DfaStateId = 1;
-  while (DfaStateId <= DfaStates.size())
-    visitDfaState(DfaStates[DfaStateId++]);
+  while (DfaStateId <= DfaStates.size()) {
+    DfaState S = DfaStates[DfaStateId];
+    visitDfaState(S);
+    DfaStateId++;
+  }
 }
 
 void DfaEmitter::emit(StringRef Name, raw_ostream &OS) {
index 76de8f7..f7724ce 100644 (file)
@@ -99,7 +99,7 @@ private:
   void constructDfa();
   /// Visit a single DFA state and construct all possible transitions to new DFA
   /// states.
-  void visitDfaState(DfaState DS);
+  void visitDfaState(const DfaState &DS);
 };
 
 } // namespace llvm