Reid Kleckner | 60b640b | 2015-05-28 22:47:01 +0000 | [diff] [blame] | 1 | //===-- CodeGen/AsmPrinter/WinException.cpp - Dwarf Exception Impl ------===// |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains support for writing Win64 exception info into asm files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Reid Kleckner | 60b640b | 2015-05-28 22:47:01 +0000 | [diff] [blame] | 14 | #include "WinException.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallString.h" |
| 16 | #include "llvm/ADT/StringExtras.h" |
| 17 | #include "llvm/ADT/Twine.h" |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/AsmPrinter.h" |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 20 | #include "llvm/CodeGen/MachineFunction.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineModuleInfo.h" |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/WinEHFuncInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 23 | #include "llvm/IR/DataLayout.h" |
Rafael Espindola | 894843c | 2014-01-07 21:19:40 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Mangler.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 25 | #include "llvm/IR/Module.h" |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCAsmInfo.h" |
| 27 | #include "llvm/MC/MCContext.h" |
| 28 | #include "llvm/MC/MCExpr.h" |
| 29 | #include "llvm/MC/MCSection.h" |
| 30 | #include "llvm/MC/MCStreamer.h" |
| 31 | #include "llvm/MC/MCSymbol.h" |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 32 | #include "llvm/MC/MCWin64EH.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Dwarf.h" |
| 34 | #include "llvm/Support/ErrorHandling.h" |
| 35 | #include "llvm/Support/FormattedStream.h" |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 36 | #include "llvm/Target/TargetFrameLowering.h" |
| 37 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 38 | #include "llvm/Target/TargetOptions.h" |
| 39 | #include "llvm/Target/TargetRegisterInfo.h" |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 40 | using namespace llvm; |
| 41 | |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 42 | WinException::WinException(AsmPrinter *A) : EHStreamer(A) { |
| 43 | // MSVC's EH tables are always composed of 32-bit words. All known 64-bit |
| 44 | // platforms use an imagerel32 relocation to refer to symbols. |
| 45 | useImageRel32 = (A->getDataLayout().getPointerSizeInBits() == 64); |
| 46 | } |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 47 | |
Reid Kleckner | 60b640b | 2015-05-28 22:47:01 +0000 | [diff] [blame] | 48 | WinException::~WinException() {} |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 49 | |
Timur Iskhodzhanov | 119f307 | 2013-11-26 13:34:55 +0000 | [diff] [blame] | 50 | /// endModule - Emit all exception information that should come after the |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 51 | /// content. |
Reid Kleckner | 60b640b | 2015-05-28 22:47:01 +0000 | [diff] [blame] | 52 | void WinException::endModule() { |
Reid Kleckner | 2bc93ca | 2015-06-10 01:02:30 +0000 | [diff] [blame^] | 53 | auto &OS = *Asm->OutStreamer; |
| 54 | const Module *M = MMI->getModule(); |
| 55 | for (const Function &F : *M) { |
| 56 | if (F.hasFnAttribute("safeseh")) { |
| 57 | llvm::errs() << ".safeseh " << F.getName() << "\n"; |
| 58 | OS.EmitCOFFSafeSEH(Asm->getSymbol(&F)); |
| 59 | } |
| 60 | } |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Reid Kleckner | 60b640b | 2015-05-28 22:47:01 +0000 | [diff] [blame] | 63 | void WinException::beginFunction(const MachineFunction *MF) { |
Charles Davis | 5638b9f | 2011-05-28 04:21:04 +0000 | [diff] [blame] | 64 | shouldEmitMoves = shouldEmitPersonality = shouldEmitLSDA = false; |
| 65 | |
| 66 | // If any landing pads survive, we need an EH table. |
| 67 | bool hasLandingPads = !MMI->getLandingPads().empty(); |
| 68 | |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 69 | const Function *F = MF->getFunction(); |
| 70 | const Function *ParentF = MMI->getWinEHParent(F); |
| 71 | |
Charles Davis | 5638b9f | 2011-05-28 04:21:04 +0000 | [diff] [blame] | 72 | shouldEmitMoves = Asm->needsSEHMoves(); |
| 73 | |
| 74 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
| 75 | unsigned PerEncoding = TLOF.getPersonalityEncoding(); |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 76 | const Function *Per = MMI->getPersonality(); |
Charles Davis | 5638b9f | 2011-05-28 04:21:04 +0000 | [diff] [blame] | 77 | |
| 78 | shouldEmitPersonality = hasLandingPads && |
| 79 | PerEncoding != dwarf::DW_EH_PE_omit && Per; |
| 80 | |
| 81 | unsigned LSDAEncoding = TLOF.getLSDAEncoding(); |
| 82 | shouldEmitLSDA = shouldEmitPersonality && |
| 83 | LSDAEncoding != dwarf::DW_EH_PE_omit; |
| 84 | |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 85 | // If we're not using CFI, we don't want the CFI or the personality. Emit the |
| 86 | // LSDA if this is the parent function. |
| 87 | if (!Asm->MAI->usesWindowsCFI()) { |
| 88 | shouldEmitLSDA = (hasLandingPads && F == ParentF); |
| 89 | shouldEmitPersonality = false; |
| 90 | return; |
| 91 | } |
David Majnemer | a225a19 | 2015-03-31 22:35:44 +0000 | [diff] [blame] | 92 | |
| 93 | // If this was an outlined handler, we need to define the label corresponding |
| 94 | // to the offset of the parent frame relative to the stack pointer after the |
| 95 | // prologue. |
David Majnemer | a225a19 | 2015-03-31 22:35:44 +0000 | [diff] [blame] | 96 | if (F != ParentF) { |
| 97 | WinEHFuncInfo &FuncInfo = MMI->getWinEHFuncInfo(ParentF); |
| 98 | auto I = FuncInfo.CatchHandlerParentFrameObjOffset.find(F); |
| 99 | if (I != FuncInfo.CatchHandlerParentFrameObjOffset.end()) { |
| 100 | MCSymbol *HandlerTypeParentFrameOffset = |
| 101 | Asm->OutContext.getOrCreateParentFrameOffsetSymbol( |
| 102 | GlobalValue::getRealLinkageName(F->getName())); |
| 103 | |
| 104 | // Emit a symbol assignment. |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 105 | Asm->OutStreamer->EmitAssignment( |
David Majnemer | a225a19 | 2015-03-31 22:35:44 +0000 | [diff] [blame] | 106 | HandlerTypeParentFrameOffset, |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 107 | MCConstantExpr::create(I->second, Asm->OutContext)); |
David Majnemer | a225a19 | 2015-03-31 22:35:44 +0000 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 111 | if (shouldEmitMoves || shouldEmitPersonality) |
| 112 | Asm->OutStreamer->EmitWinCFIStartProc(Asm->CurrentFnSym); |
Charles Davis | 5638b9f | 2011-05-28 04:21:04 +0000 | [diff] [blame] | 113 | |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 114 | if (shouldEmitPersonality) { |
| 115 | const MCSymbol *PersHandlerSym = |
| 116 | TLOF.getCFIPersonalitySymbol(Per, *Asm->Mang, Asm->TM, MMI); |
| 117 | Asm->OutStreamer->EmitWinEHHandler(PersHandlerSym, true, true); |
| 118 | } |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Timur Iskhodzhanov | 119f307 | 2013-11-26 13:34:55 +0000 | [diff] [blame] | 121 | /// endFunction - Gather and emit post-function exception information. |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 122 | /// |
Reid Kleckner | 60b640b | 2015-05-28 22:47:01 +0000 | [diff] [blame] | 123 | void WinException::endFunction(const MachineFunction *MF) { |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 124 | if (!shouldEmitPersonality && !shouldEmitMoves && !shouldEmitLSDA) |
Charles Davis | 5638b9f | 2011-05-28 04:21:04 +0000 | [diff] [blame] | 125 | return; |
| 126 | |
Reid Kleckner | 3e9fadf | 2015-04-15 18:48:15 +0000 | [diff] [blame] | 127 | EHPersonality Per = MMI->getPersonalityType(); |
| 128 | |
| 129 | // Get rid of any dead landing pads if we're not using a Windows EH scheme. In |
| 130 | // Windows EH schemes, the landing pad is not actually reachable. It only |
| 131 | // exists so that we can emit the right table data. |
| 132 | if (!isMSVCEHPersonality(Per)) |
| 133 | MMI->TidyLandingPads(); |
Charles Davis | a575226 | 2011-05-30 00:13:34 +0000 | [diff] [blame] | 134 | |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 135 | if (shouldEmitPersonality || shouldEmitLSDA) { |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 136 | Asm->OutStreamer->PushSection(); |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 137 | |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 138 | if (shouldEmitMoves || shouldEmitPersonality) { |
| 139 | // Emit an UNWIND_INFO struct describing the prologue. |
| 140 | Asm->OutStreamer->EmitWinEHHandlerData(); |
| 141 | } else { |
| 142 | // Just switch sections to the right xdata section. This use of |
| 143 | // CurrentFnSym assumes that we only emit the LSDA when ending the parent |
| 144 | // function. |
| 145 | MCSection *XData = WinEH::UnwindEmitter::getXDataSection( |
| 146 | Asm->CurrentFnSym, Asm->OutContext); |
| 147 | Asm->OutStreamer->SwitchSection(XData); |
| 148 | } |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 149 | |
Reid Kleckner | 9b5eaf0 | 2015-01-14 18:50:10 +0000 | [diff] [blame] | 150 | // Emit the tables appropriate to the personality function in use. If we |
| 151 | // don't recognize the personality, assume it uses an Itanium-style LSDA. |
Reid Kleckner | 2d5fb68 | 2015-02-14 00:21:02 +0000 | [diff] [blame] | 152 | if (Per == EHPersonality::MSVC_Win64SEH) |
Reid Kleckner | 9b5eaf0 | 2015-01-14 18:50:10 +0000 | [diff] [blame] | 153 | emitCSpecificHandlerTable(); |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 154 | else if (Per == EHPersonality::MSVC_X86SEH) |
Reid Kleckner | f12c030 | 2015-06-09 21:42:19 +0000 | [diff] [blame] | 155 | emitExceptHandlerTable(MF); |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 156 | else if (Per == EHPersonality::MSVC_CXX) |
| 157 | emitCXXFrameHandler3Table(MF); |
Reid Kleckner | 9b5eaf0 | 2015-01-14 18:50:10 +0000 | [diff] [blame] | 158 | else |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 159 | emitExceptionTable(); |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 160 | |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 161 | Asm->OutStreamer->PopSection(); |
Charles Davis | a575226 | 2011-05-30 00:13:34 +0000 | [diff] [blame] | 162 | } |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 163 | |
| 164 | if (shouldEmitMoves) |
| 165 | Asm->OutStreamer->EmitWinCFIEndProc(); |
Charles Davis | 91ed799 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 166 | } |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 167 | |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 168 | const MCExpr *WinException::create32bitRef(const MCSymbol *Value) { |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 169 | if (!Value) |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 170 | return MCConstantExpr::create(0, Asm->OutContext); |
| 171 | return MCSymbolRefExpr::create(Value, useImageRel32 |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 172 | ? MCSymbolRefExpr::VK_COFF_IMGREL32 |
| 173 | : MCSymbolRefExpr::VK_None, |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 174 | Asm->OutContext); |
| 175 | } |
| 176 | |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 177 | const MCExpr *WinException::create32bitRef(const GlobalValue *GV) { |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 178 | if (!GV) |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 179 | return MCConstantExpr::create(0, Asm->OutContext); |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 180 | return create32bitRef(Asm->getSymbol(GV)); |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 183 | /// Emit the language-specific data that __C_specific_handler expects. This |
| 184 | /// handler lives in the x64 Microsoft C runtime and allows catching or cleaning |
| 185 | /// up after faults with __try, __except, and __finally. The typeinfo values |
| 186 | /// are not really RTTI data, but pointers to filter functions that return an |
| 187 | /// integer (1, 0, or -1) indicating how to handle the exception. For __finally |
| 188 | /// blocks and other cleanups, the landing pad label is zero, and the filter |
| 189 | /// function is actually a cleanup handler with the same prototype. A catch-all |
| 190 | /// entry is modeled with a null filter function field and a non-zero landing |
| 191 | /// pad label. |
| 192 | /// |
| 193 | /// Possible filter function return values: |
| 194 | /// EXCEPTION_EXECUTE_HANDLER (1): |
| 195 | /// Jump to the landing pad label after cleanups. |
| 196 | /// EXCEPTION_CONTINUE_SEARCH (0): |
| 197 | /// Continue searching this table or continue unwinding. |
| 198 | /// EXCEPTION_CONTINUE_EXECUTION (-1): |
| 199 | /// Resume execution at the trapping PC. |
| 200 | /// |
| 201 | /// Inferred table structure: |
| 202 | /// struct Table { |
| 203 | /// int NumEntries; |
| 204 | /// struct Entry { |
| 205 | /// imagerel32 LabelStart; |
| 206 | /// imagerel32 LabelEnd; |
Reid Kleckner | f690f50 | 2015-01-22 02:27:44 +0000 | [diff] [blame] | 207 | /// imagerel32 FilterOrFinally; // One means catch-all. |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 208 | /// imagerel32 LabelLPad; // Zero means __finally. |
| 209 | /// } Entries[NumEntries]; |
| 210 | /// }; |
Reid Kleckner | 60b640b | 2015-05-28 22:47:01 +0000 | [diff] [blame] | 211 | void WinException::emitCSpecificHandlerTable() { |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 212 | const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads(); |
| 213 | |
| 214 | // Simplifying assumptions for first implementation: |
| 215 | // - Cleanups are not implemented. |
| 216 | // - Filters are not implemented. |
| 217 | |
| 218 | // The Itanium LSDA table sorts similar landing pads together to simplify the |
| 219 | // actions table, but we don't need that. |
| 220 | SmallVector<const LandingPadInfo *, 64> LandingPads; |
| 221 | LandingPads.reserve(PadInfos.size()); |
| 222 | for (const auto &LP : PadInfos) |
| 223 | LandingPads.push_back(&LP); |
| 224 | |
| 225 | // Compute label ranges for call sites as we would for the Itanium LSDA, but |
| 226 | // use an all zero action table because we aren't using these actions. |
| 227 | SmallVector<unsigned, 64> FirstActions; |
| 228 | FirstActions.resize(LandingPads.size()); |
| 229 | SmallVector<CallSiteEntry, 64> CallSites; |
| 230 | computeCallSiteTable(CallSites, LandingPads, FirstActions); |
| 231 | |
Rafael Espindola | 629cdba | 2015-02-27 18:18:39 +0000 | [diff] [blame] | 232 | MCSymbol *EHFuncBeginSym = Asm->getFunctionBegin(); |
| 233 | MCSymbol *EHFuncEndSym = Asm->getFunctionEnd(); |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 234 | |
| 235 | // Emit the number of table entries. |
| 236 | unsigned NumEntries = 0; |
| 237 | for (const CallSiteEntry &CSE : CallSites) { |
| 238 | if (!CSE.LPad) |
| 239 | continue; // Ignore gaps. |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 240 | NumEntries += CSE.LPad->SEHHandlers.size(); |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 241 | } |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 242 | Asm->OutStreamer->EmitIntValue(NumEntries, 4); |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 243 | |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 244 | // If there are no actions, we don't need to iterate again. |
| 245 | if (NumEntries == 0) |
| 246 | return; |
| 247 | |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 248 | // Emit the four-label records for each call site entry. The table has to be |
| 249 | // sorted in layout order, and the call sites should already be sorted. |
| 250 | for (const CallSiteEntry &CSE : CallSites) { |
| 251 | // Ignore gaps. Unlike the Itanium model, unwinding through a frame without |
| 252 | // an EH table entry will propagate the exception rather than terminating |
| 253 | // the program. |
| 254 | if (!CSE.LPad) |
| 255 | continue; |
| 256 | const LandingPadInfo *LPad = CSE.LPad; |
| 257 | |
| 258 | // Compute the label range. We may reuse the function begin and end labels |
| 259 | // rather than forming new ones. |
| 260 | const MCExpr *Begin = |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 261 | create32bitRef(CSE.BeginLabel ? CSE.BeginLabel : EHFuncBeginSym); |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 262 | const MCExpr *End; |
| 263 | if (CSE.EndLabel) { |
| 264 | // The interval is half-open, so we have to add one to include the return |
| 265 | // address of the last invoke in the range. |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 266 | End = MCBinaryExpr::createAdd(create32bitRef(CSE.EndLabel), |
| 267 | MCConstantExpr::create(1, Asm->OutContext), |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 268 | Asm->OutContext); |
| 269 | } else { |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 270 | End = create32bitRef(EHFuncEndSym); |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 273 | // Emit an entry for each action. |
| 274 | for (SEHHandler Handler : LPad->SEHHandlers) { |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 275 | Asm->OutStreamer->EmitValue(Begin, 4); |
| 276 | Asm->OutStreamer->EmitValue(End, 4); |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 277 | |
| 278 | // Emit the filter or finally function pointer, if present. Otherwise, |
| 279 | // emit '1' to indicate a catch-all. |
| 280 | const Function *F = Handler.FilterOrFinally; |
| 281 | if (F) |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 282 | Asm->OutStreamer->EmitValue(create32bitRef(Asm->getSymbol(F)), 4); |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 283 | else |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 284 | Asm->OutStreamer->EmitIntValue(1, 4); |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 285 | |
| 286 | // Emit the recovery address, if present. Otherwise, this must be a |
| 287 | // finally. |
| 288 | const BlockAddress *BA = Handler.RecoverBA; |
| 289 | if (BA) |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 290 | Asm->OutStreamer->EmitValue( |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 291 | create32bitRef(Asm->GetBlockAddressSymbol(BA)), 4); |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 292 | else |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 293 | Asm->OutStreamer->EmitIntValue(0, 4); |
Reid Kleckner | d2a1a51 | 2015-04-21 18:23:57 +0000 | [diff] [blame] | 294 | } |
Reid Kleckner | 0a57f65 | 2015-01-14 01:05:27 +0000 | [diff] [blame] | 295 | } |
| 296 | } |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 297 | |
Reid Kleckner | 60b640b | 2015-05-28 22:47:01 +0000 | [diff] [blame] | 298 | void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) { |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 299 | const Function *F = MF->getFunction(); |
| 300 | const Function *ParentF = MMI->getWinEHParent(F); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 301 | auto &OS = *Asm->OutStreamer; |
David Majnemer | a225a19 | 2015-03-31 22:35:44 +0000 | [diff] [blame] | 302 | WinEHFuncInfo &FuncInfo = MMI->getWinEHFuncInfo(ParentF); |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 303 | |
| 304 | StringRef ParentLinkageName = |
| 305 | GlobalValue::getRealLinkageName(ParentF->getName()); |
| 306 | |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 307 | MCSymbol *FuncInfoXData = nullptr; |
| 308 | if (shouldEmitPersonality) { |
| 309 | FuncInfoXData = Asm->OutContext.getOrCreateSymbol( |
| 310 | Twine("$cppxdata$", ParentLinkageName)); |
| 311 | OS.EmitValue(create32bitRef(FuncInfoXData), 4); |
| 312 | |
| 313 | extendIP2StateTable(MF, ParentF, FuncInfo); |
| 314 | |
| 315 | // Defer emission until we've visited the parent function and all the catch |
| 316 | // handlers. Cleanups don't contribute to the ip2state table, so don't count |
| 317 | // them. |
| 318 | if (ParentF != F && !FuncInfo.CatchHandlerMaxState.count(F)) |
| 319 | return; |
| 320 | ++FuncInfo.NumIPToStateFuncsVisited; |
| 321 | if (FuncInfo.NumIPToStateFuncsVisited != FuncInfo.CatchHandlerMaxState.size()) |
| 322 | return; |
| 323 | } else { |
| 324 | FuncInfoXData = Asm->OutContext.getOrCreateLSDASymbol(ParentLinkageName); |
| 325 | } |
| 326 | |
| 327 | MCSymbol *UnwindMapXData = nullptr; |
| 328 | MCSymbol *TryBlockMapXData = nullptr; |
| 329 | MCSymbol *IPToStateXData = nullptr; |
| 330 | if (!FuncInfo.UnwindMap.empty()) |
| 331 | UnwindMapXData = Asm->OutContext.getOrCreateSymbol( |
| 332 | Twine("$stateUnwindMap$", ParentLinkageName)); |
| 333 | if (!FuncInfo.TryBlockMap.empty()) |
| 334 | TryBlockMapXData = Asm->OutContext.getOrCreateSymbol( |
| 335 | Twine("$tryMap$", ParentLinkageName)); |
| 336 | if (!FuncInfo.IPToStateList.empty()) |
| 337 | IPToStateXData = Asm->OutContext.getOrCreateSymbol( |
| 338 | Twine("$ip2state$", ParentLinkageName)); |
| 339 | |
| 340 | // FuncInfo { |
| 341 | // uint32_t MagicNumber |
| 342 | // int32_t MaxState; |
| 343 | // UnwindMapEntry *UnwindMap; |
| 344 | // uint32_t NumTryBlocks; |
| 345 | // TryBlockMapEntry *TryBlockMap; |
| 346 | // uint32_t IPMapEntries; // always 0 for x86 |
| 347 | // IPToStateMapEntry *IPToStateMap; // always 0 for x86 |
| 348 | // uint32_t UnwindHelp; // non-x86 only |
| 349 | // ESTypeList *ESTypeList; |
| 350 | // int32_t EHFlags; |
| 351 | // } |
| 352 | // EHFlags & 1 -> Synchronous exceptions only, no async exceptions. |
| 353 | // EHFlags & 2 -> ??? |
| 354 | // EHFlags & 4 -> The function is noexcept(true), unwinding can't continue. |
| 355 | OS.EmitLabel(FuncInfoXData); |
| 356 | OS.EmitIntValue(0x19930522, 4); // MagicNumber |
| 357 | OS.EmitIntValue(FuncInfo.UnwindMap.size(), 4); // MaxState |
| 358 | OS.EmitValue(create32bitRef(UnwindMapXData), 4); // UnwindMap |
| 359 | OS.EmitIntValue(FuncInfo.TryBlockMap.size(), 4); // NumTryBlocks |
| 360 | OS.EmitValue(create32bitRef(TryBlockMapXData), 4); // TryBlockMap |
| 361 | OS.EmitIntValue(FuncInfo.IPToStateList.size(), 4); // IPMapEntries |
| 362 | OS.EmitValue(create32bitRef(IPToStateXData), 4); // IPToStateMap |
| 363 | if (Asm->MAI->usesWindowsCFI()) |
| 364 | OS.EmitIntValue(FuncInfo.UnwindHelpFrameOffset, 4); // UnwindHelp |
| 365 | OS.EmitIntValue(0, 4); // ESTypeList |
| 366 | OS.EmitIntValue(1, 4); // EHFlags |
| 367 | |
| 368 | // UnwindMapEntry { |
| 369 | // int32_t ToState; |
| 370 | // void (*Action)(); |
| 371 | // }; |
| 372 | if (UnwindMapXData) { |
| 373 | OS.EmitLabel(UnwindMapXData); |
| 374 | for (const WinEHUnwindMapEntry &UME : FuncInfo.UnwindMap) { |
| 375 | OS.EmitIntValue(UME.ToState, 4); // ToState |
| 376 | OS.EmitValue(create32bitRef(UME.Cleanup), 4); // Action |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | // TryBlockMap { |
| 381 | // int32_t TryLow; |
| 382 | // int32_t TryHigh; |
| 383 | // int32_t CatchHigh; |
| 384 | // int32_t NumCatches; |
| 385 | // HandlerType *HandlerArray; |
| 386 | // }; |
| 387 | if (TryBlockMapXData) { |
| 388 | OS.EmitLabel(TryBlockMapXData); |
| 389 | SmallVector<MCSymbol *, 1> HandlerMaps; |
| 390 | for (size_t I = 0, E = FuncInfo.TryBlockMap.size(); I != E; ++I) { |
| 391 | WinEHTryBlockMapEntry &TBME = FuncInfo.TryBlockMap[I]; |
| 392 | MCSymbol *HandlerMapXData = nullptr; |
| 393 | |
| 394 | if (!TBME.HandlerArray.empty()) |
| 395 | HandlerMapXData = |
| 396 | Asm->OutContext.getOrCreateSymbol(Twine("$handlerMap$") |
| 397 | .concat(Twine(I)) |
| 398 | .concat("$") |
| 399 | .concat(ParentLinkageName)); |
| 400 | |
| 401 | HandlerMaps.push_back(HandlerMapXData); |
| 402 | |
| 403 | int CatchHigh = -1; |
| 404 | for (WinEHHandlerType &HT : TBME.HandlerArray) |
| 405 | CatchHigh = |
| 406 | std::max(CatchHigh, FuncInfo.CatchHandlerMaxState[HT.Handler]); |
| 407 | |
| 408 | assert(TBME.TryLow <= TBME.TryHigh); |
| 409 | OS.EmitIntValue(TBME.TryLow, 4); // TryLow |
| 410 | OS.EmitIntValue(TBME.TryHigh, 4); // TryHigh |
| 411 | OS.EmitIntValue(CatchHigh, 4); // CatchHigh |
| 412 | OS.EmitIntValue(TBME.HandlerArray.size(), 4); // NumCatches |
| 413 | OS.EmitValue(create32bitRef(HandlerMapXData), 4); // HandlerArray |
| 414 | } |
| 415 | |
| 416 | for (size_t I = 0, E = FuncInfo.TryBlockMap.size(); I != E; ++I) { |
| 417 | WinEHTryBlockMapEntry &TBME = FuncInfo.TryBlockMap[I]; |
| 418 | MCSymbol *HandlerMapXData = HandlerMaps[I]; |
| 419 | if (!HandlerMapXData) |
| 420 | continue; |
| 421 | // HandlerType { |
| 422 | // int32_t Adjectives; |
| 423 | // TypeDescriptor *Type; |
| 424 | // int32_t CatchObjOffset; |
| 425 | // void (*Handler)(); |
| 426 | // int32_t ParentFrameOffset; // x64 only |
| 427 | // }; |
| 428 | OS.EmitLabel(HandlerMapXData); |
| 429 | for (const WinEHHandlerType &HT : TBME.HandlerArray) { |
| 430 | // Get the frame escape label with the offset of the catch object. If |
| 431 | // the index is -1, then there is no catch object, and we should emit an |
| 432 | // offset of zero, indicating that no copy will occur. |
| 433 | const MCExpr *FrameAllocOffsetRef = nullptr; |
| 434 | if (HT.CatchObjRecoverIdx >= 0) { |
| 435 | MCSymbol *FrameAllocOffset = |
| 436 | Asm->OutContext.getOrCreateFrameAllocSymbol( |
| 437 | GlobalValue::getRealLinkageName(ParentF->getName()), |
| 438 | HT.CatchObjRecoverIdx); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 439 | FrameAllocOffsetRef = MCSymbolRefExpr::create( |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 440 | FrameAllocOffset, MCSymbolRefExpr::VK_None, Asm->OutContext); |
| 441 | } else { |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 442 | FrameAllocOffsetRef = MCConstantExpr::create(0, Asm->OutContext); |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | OS.EmitIntValue(HT.Adjectives, 4); // Adjectives |
| 446 | OS.EmitValue(create32bitRef(HT.TypeDescriptor), 4); // Type |
| 447 | OS.EmitValue(FrameAllocOffsetRef, 4); // CatchObjOffset |
| 448 | OS.EmitValue(create32bitRef(HT.Handler), 4); // Handler |
| 449 | |
| 450 | if (shouldEmitPersonality) { |
| 451 | MCSymbol *ParentFrameOffset = |
| 452 | Asm->OutContext.getOrCreateParentFrameOffsetSymbol( |
| 453 | GlobalValue::getRealLinkageName(HT.Handler->getName())); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 454 | const MCSymbolRefExpr *ParentFrameOffsetRef = MCSymbolRefExpr::create( |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 455 | ParentFrameOffset, MCSymbolRefExpr::VK_None, Asm->OutContext); |
| 456 | OS.EmitValue(ParentFrameOffsetRef, 4); // ParentFrameOffset |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | // IPToStateMapEntry { |
| 463 | // void *IP; |
| 464 | // int32_t State; |
| 465 | // }; |
| 466 | if (IPToStateXData) { |
| 467 | OS.EmitLabel(IPToStateXData); |
| 468 | for (auto &IPStatePair : FuncInfo.IPToStateList) { |
| 469 | OS.EmitValue(create32bitRef(IPStatePair.first), 4); // IP |
| 470 | OS.EmitIntValue(IPStatePair.second, 4); // State |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | void WinException::extendIP2StateTable(const MachineFunction *MF, |
| 476 | const Function *ParentF, |
| 477 | WinEHFuncInfo &FuncInfo) { |
| 478 | const Function *F = MF->getFunction(); |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 479 | |
| 480 | // The Itanium LSDA table sorts similar landing pads together to simplify the |
| 481 | // actions table, but we don't need that. |
| 482 | SmallVector<const LandingPadInfo *, 64> LandingPads; |
| 483 | const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads(); |
| 484 | LandingPads.reserve(PadInfos.size()); |
| 485 | for (const auto &LP : PadInfos) |
| 486 | LandingPads.push_back(&LP); |
| 487 | |
| 488 | RangeMapType PadMap; |
| 489 | computePadMap(LandingPads, PadMap); |
| 490 | |
| 491 | // The end label of the previous invoke or nounwind try-range. |
| 492 | MCSymbol *LastLabel = Asm->getFunctionBegin(); |
| 493 | |
| 494 | // Whether there is a potentially throwing instruction (currently this means |
| 495 | // an ordinary call) between the end of the previous try-range and now. |
| 496 | bool SawPotentiallyThrowing = false; |
| 497 | |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 498 | int LastEHState = -2; |
| 499 | |
| 500 | // The parent function and the catch handlers contribute to the 'ip2state' |
| 501 | // table. |
Andrew Kaylor | 762a6be | 2015-05-11 19:41:19 +0000 | [diff] [blame] | 502 | |
| 503 | // Include ip2state entries for the beginning of the main function and |
| 504 | // for catch handler functions. |
| 505 | if (F == ParentF) { |
| 506 | FuncInfo.IPToStateList.push_back(std::make_pair(LastLabel, -1)); |
| 507 | LastEHState = -1; |
| 508 | } else if (FuncInfo.HandlerBaseState.count(F)) { |
Reid Kleckner | 1d3d4ad | 2015-05-29 17:00:57 +0000 | [diff] [blame] | 509 | FuncInfo.IPToStateList.push_back( |
| 510 | std::make_pair(LastLabel, FuncInfo.HandlerBaseState[F])); |
Andrew Kaylor | 762a6be | 2015-05-11 19:41:19 +0000 | [diff] [blame] | 511 | LastEHState = FuncInfo.HandlerBaseState[F]; |
| 512 | } |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 513 | for (const auto &MBB : *MF) { |
| 514 | for (const auto &MI : MBB) { |
| 515 | if (!MI.isEHLabel()) { |
| 516 | if (MI.isCall()) |
| 517 | SawPotentiallyThrowing |= !callToNoUnwindFunction(&MI); |
| 518 | continue; |
| 519 | } |
| 520 | |
| 521 | // End of the previous try-range? |
| 522 | MCSymbol *BeginLabel = MI.getOperand(0).getMCSymbol(); |
| 523 | if (BeginLabel == LastLabel) |
| 524 | SawPotentiallyThrowing = false; |
| 525 | |
| 526 | // Beginning of a new try-range? |
| 527 | RangeMapType::const_iterator L = PadMap.find(BeginLabel); |
| 528 | if (L == PadMap.end()) |
| 529 | // Nope, it was just some random label. |
| 530 | continue; |
| 531 | |
| 532 | const PadRange &P = L->second; |
| 533 | const LandingPadInfo *LandingPad = LandingPads[P.PadIndex]; |
| 534 | assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] && |
| 535 | "Inconsistent landing pad map!"); |
| 536 | |
Andrew Kaylor | 762a6be | 2015-05-11 19:41:19 +0000 | [diff] [blame] | 537 | // FIXME: Should this be using FuncInfo.HandlerBaseState? |
| 538 | if (SawPotentiallyThrowing && LastEHState != -1) { |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 539 | FuncInfo.IPToStateList.push_back(std::make_pair(LastLabel, -1)); |
| 540 | SawPotentiallyThrowing = false; |
| 541 | LastEHState = -1; |
| 542 | } |
| 543 | |
| 544 | if (LandingPad->WinEHState != LastEHState) |
| 545 | FuncInfo.IPToStateList.push_back( |
| 546 | std::make_pair(BeginLabel, LandingPad->WinEHState)); |
| 547 | LastEHState = LandingPad->WinEHState; |
| 548 | LastLabel = LandingPad->EndLabels[P.RangeIndex]; |
| 549 | } |
| 550 | } |
David Majnemer | cde3303 | 2015-03-30 22:58:10 +0000 | [diff] [blame] | 551 | } |
Reid Kleckner | f12c030 | 2015-06-09 21:42:19 +0000 | [diff] [blame] | 552 | |
| 553 | /// Emit the language-specific data that _except_handler3 and 4 expect. This is |
| 554 | /// functionally equivalent to the __C_specific_handler table, except it is |
| 555 | /// indexed by state number instead of IP. |
| 556 | void WinException::emitExceptHandlerTable(const MachineFunction *MF) { |
| 557 | auto &OS = *Asm->OutStreamer; |
| 558 | |
| 559 | // Emit the __ehtable label that we use for llvm.x86.seh.lsda. |
| 560 | const Function *F = MF->getFunction(); |
| 561 | StringRef FLinkageName = GlobalValue::getRealLinkageName(F->getName()); |
| 562 | MCSymbol *LSDALabel = Asm->OutContext.getOrCreateLSDASymbol(FLinkageName); |
| 563 | OS.EmitLabel(LSDALabel); |
| 564 | |
| 565 | const Function *Per = MMI->getPersonality(); |
| 566 | StringRef PerName = Per->getName(); |
| 567 | int BaseState = -1; |
| 568 | if (PerName == "_except_handler4") { |
| 569 | // The LSDA for _except_handler4 starts with this struct, followed by the |
| 570 | // scope table: |
| 571 | // |
| 572 | // struct EH4ScopeTable { |
| 573 | // int32_t GSCookieOffset; |
| 574 | // int32_t GSCookieXOROffset; |
| 575 | // int32_t EHCookieOffset; |
| 576 | // int32_t EHCookieXOROffset; |
| 577 | // ScopeTableEntry ScopeRecord[]; |
| 578 | // }; |
| 579 | // |
| 580 | // Only the EHCookieOffset field appears to vary, and it appears to be the |
| 581 | // offset from the final saved SP value to the retaddr. |
| 582 | OS.EmitIntValue(-2, 4); |
| 583 | OS.EmitIntValue(0, 4); |
| 584 | // FIXME: Calculate. |
| 585 | OS.EmitIntValue(9999, 4); |
| 586 | OS.EmitIntValue(0, 4); |
| 587 | BaseState = -2; |
| 588 | } |
| 589 | |
| 590 | // Build a list of pointers to LandingPadInfos and then sort by WinEHState. |
| 591 | const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads(); |
| 592 | SmallVector<const LandingPadInfo *, 4> LPads; |
| 593 | LPads.reserve((PadInfos.size())); |
| 594 | for (const LandingPadInfo &LPInfo : PadInfos) |
| 595 | LPads.push_back(&LPInfo); |
| 596 | std::sort(LPads.begin(), LPads.end(), |
| 597 | [](const LandingPadInfo *L, const LandingPadInfo *R) { |
| 598 | return L->WinEHState < R->WinEHState; |
| 599 | }); |
| 600 | |
| 601 | // For each action in each lpad, emit one of these: |
| 602 | // struct ScopeTableEntry { |
| 603 | // int32_t EnclosingLevel; |
| 604 | // int32_t (__cdecl *FilterOrFinally)(); |
| 605 | // void *HandlerLabel; |
| 606 | // }; |
| 607 | // |
| 608 | // The "outermost" action will use BaseState as its enclosing level. Each |
| 609 | // other action will refer to the previous state as its enclosing level. |
| 610 | int CurState = 0; |
| 611 | for (const LandingPadInfo *LPInfo : LPads) { |
| 612 | int EnclosingLevel = BaseState; |
Reid Kleckner | 7912d9b | 2015-06-10 00:04:53 +0000 | [diff] [blame] | 613 | assert(CurState + int(LPInfo->SEHHandlers.size()) - 1 == |
| 614 | LPInfo->WinEHState && |
Reid Kleckner | f12c030 | 2015-06-09 21:42:19 +0000 | [diff] [blame] | 615 | "gaps in the SEH scope table"); |
| 616 | for (const SEHHandler &Handler : LPInfo->SEHHandlers) { |
| 617 | // Emit the filter or finally function pointer, if present. Otherwise, |
| 618 | // emit '1' to indicate a catch-all. |
| 619 | const MCExpr *FilterOrFinally; |
| 620 | if (const Function *F = Handler.FilterOrFinally) |
| 621 | FilterOrFinally = create32bitRef(Asm->getSymbol(F)); |
| 622 | else |
| 623 | FilterOrFinally = MCConstantExpr::create(1, Asm->OutContext); |
| 624 | |
| 625 | // Compute the recovery address, which is a block address or null. |
| 626 | const BlockAddress *BA = Handler.RecoverBA; |
| 627 | const MCExpr *RecoverBBOrNull = |
| 628 | create32bitRef(BA ? Asm->GetBlockAddressSymbol(BA) : nullptr); |
| 629 | |
| 630 | OS.EmitIntValue(EnclosingLevel, 4); |
| 631 | OS.EmitValue(FilterOrFinally, 4); |
| 632 | OS.EmitValue(RecoverBBOrNull, 4); |
| 633 | |
| 634 | // The next state unwinds to this state. |
| 635 | EnclosingLevel = CurState; |
| 636 | CurState++; |
| 637 | } |
| 638 | } |
| 639 | } |