[llvm-branch-commits] [llvm] 2905a48 - Fix DfaEmitter::visitDfaState() crash in MSVC x86 debug builds (PR44945)

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 25 06:22:09 PST 2020


Author: Hans Wennborg
Date: 2020-02-25T15:19:52+01:00
New Revision: 2905a48c8790b530709305e984451ddab268c8e4

URL: https://github.com/llvm/llvm-project/commit/2905a48c8790b530709305e984451ddab268c8e4
DIFF: https://github.com/llvm/llvm-project/commit/2905a48c8790b530709305e984451ddab268c8e4.diff

LOG: 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 edae4be8e21c5deb9a8ffc24a8c17e70b878bf39)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/DFAEmitter.cpp b/llvm/utils/TableGen/DFAEmitter.cpp
index dd3db7c150ba..c392651180b6 100644
--- a/llvm/utils/TableGen/DFAEmitter.cpp
+++ b/llvm/utils/TableGen/DFAEmitter.cpp
@@ -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) {

diff  --git a/llvm/utils/TableGen/DFAEmitter.h b/llvm/utils/TableGen/DFAEmitter.h
index 76de8f72cd88..f7724ce06bac 100644
--- a/llvm/utils/TableGen/DFAEmitter.h
+++ b/llvm/utils/TableGen/DFAEmitter.h
@@ -99,7 +99,7 @@ class DfaEmitter {
   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


        


More information about the llvm-branch-commits mailing list