Fix Windows/MSVC build after 6e56046f65
authorEvgeny Leviant <eleviant@accesssoftek.com>
Tue, 13 Oct 2020 12:24:58 +0000 (15:24 +0300)
committerEvgeny Leviant <eleviant@accesssoftek.com>
Tue, 13 Oct 2020 12:24:58 +0000 (15:24 +0300)
Commit 6e56046f65 may trigger SEGV in llvm-tablegen if the latter
is built with -DLLVM_OPTIMIZED_TABLEGEN=OFF. The reason of SEGV was
accessing stale memory after expansion of std::vector.

llvm/utils/TableGen/CodeGenSchedule.cpp

index f233b92..be12758 100644 (file)
@@ -1664,7 +1664,6 @@ static void inferFromTransitions(ArrayRef<PredTransition> LastTransitions,
                                  CodeGenSchedModels &SchedModels) {
   // For each PredTransition, create a new CodeGenSchedTransition, which usually
   // requires creating a new SchedClass.
-  const CodeGenSchedClass &FromSC = SchedModels.getSchedClass(FromClassIdx);
   for (ArrayRef<PredTransition>::iterator
          I = LastTransitions.begin(), E = LastTransitions.end(); I != E; ++I) {
     IdxVec OperWritesVariant, OperReadsVariant;
@@ -1674,6 +1673,7 @@ static void inferFromTransitions(ArrayRef<PredTransition> LastTransitions,
 
     // Transition should not contain processor indices already assigned to
     // InstRWs in this scheduling class.
+    const CodeGenSchedClass &FromSC = SchedModels.getSchedClass(FromClassIdx);
     llvm::copy_if(I->ProcIndices, std::back_inserter(SCTrans.ProcIndices),
                   [&FromSC](unsigned PIdx) {
                     return !FromSC.InstRWProcIndices.count(PIdx);