[llvm] edae4be - Fix DfaEmitter::visitDfaState() crash in MSVC x86 debug builds (PR44945)

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 25 06:19:21 PST 2020


Author: Hans Wennborg
Date: 2020-02-25T15:18:41+01:00
New Revision: edae4be8e21c5deb9a8ffc24a8c17e70b878bf39

URL: https://github.com/llvm/llvm-project/commit/edae4be8e21c5deb9a8ffc24a8c17e70b878bf39
DIFF: https://github.com/llvm/llvm-project/commit/edae4be8e21c5deb9a8ffc24a8c17e70b878bf39.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.

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 91c8638dd20f..7391f6845a4b 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-commits mailing list