[WinEHPrepare] Don't rely on the order of IR
[oota-llvm.git] / lib / CodeGen / AsmPrinter / Win64Exception.cpp
index a685d2e23d5fbeaf0fd3b4a8a9c831eb333bd1be..39f7875cb3fcd5be5ff63954a21e72c806abf67d 100644 (file)
@@ -343,7 +343,11 @@ void Win64Exception::emitCXXFrameHandler3Table(const MachineFunction *MF) {
     }
   }
 
-  if (ParentF != F)
+  // Defer emission until we've visited the parent function and all the catch
+  // handlers.
+  if (ParentF == F || FuncInfo.CatchHandlerMaxState.count(F))
+    ++FuncInfo.NumIPToStateFuncsVisited;
+  if (FuncInfo.NumIPToStateFuncsVisited != FuncInfo.CatchHandlerMaxState.size())
     return;
 
   MCSymbol *UnwindMapXData = nullptr;