1 //===-- X86WinEHState - Insert EH state updates for win32 exceptions ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // All functions using an MSVC EH personality use an explicitly updated state
11 // number stored in an exception registration stack object. The registration
12 // object is linked into a thread-local chain of registrations stored at fs:00.
13 // This pass adds the registration object and EH state updates.
15 //===----------------------------------------------------------------------===//
18 #include "llvm/Analysis/LibCallSemantics.h"
19 #include "llvm/CodeGen/MachineModuleInfo.h"
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/CodeGen/WinEHFuncInfo.h"
22 #include "llvm/IR/Dominators.h"
23 #include "llvm/IR/Function.h"
24 #include "llvm/IR/IRBuilder.h"
25 #include "llvm/IR/Instructions.h"
26 #include "llvm/IR/IntrinsicInst.h"
27 #include "llvm/IR/Module.h"
28 #include "llvm/IR/PatternMatch.h"
29 #include "llvm/Pass.h"
30 #include "llvm/Support/Debug.h"
31 #include "llvm/Support/raw_ostream.h"
32 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
33 #include "llvm/Transforms/Utils/Cloning.h"
34 #include "llvm/Transforms/Utils/Local.h"
37 using namespace llvm::PatternMatch;
39 #define DEBUG_TYPE "winehstate"
41 namespace llvm { void initializeWinEHStatePassPass(PassRegistry &); }
44 class WinEHStatePass : public FunctionPass {
46 static char ID; // Pass identification, replacement for typeid.
48 WinEHStatePass() : FunctionPass(ID) {
49 initializeWinEHStatePassPass(*PassRegistry::getPassRegistry());
52 bool runOnFunction(Function &Fn) override;
54 bool doInitialization(Module &M) override;
56 bool doFinalization(Module &M) override;
58 void getAnalysisUsage(AnalysisUsage &AU) const override;
60 const char *getPassName() const override {
61 return "Windows 32-bit x86 EH state insertion";
65 void emitExceptionRegistrationRecord(Function *F);
67 void linkExceptionRegistration(IRBuilder<> &Builder, Function *Handler);
68 void unlinkExceptionRegistration(IRBuilder<> &Builder);
69 void addCXXStateStores(Function &F, WinEHFuncInfo &FuncInfo);
70 void addSEHStateStores(Function &F, WinEHFuncInfo &FuncInfo);
71 void addCXXStateStoresToFunclet(Value *ParentRegNode, WinEHFuncInfo &FuncInfo,
72 Function &F, int BaseState);
73 void insertStateNumberStore(Value *ParentRegNode, Instruction *IP, int State);
75 Value *emitEHLSDA(IRBuilder<> &Builder, Function *F);
77 Function *generateLSDAInEAXThunk(Function *ParentFunc);
79 int escapeRegNode(Function &F);
81 // Module-level type getters.
82 Type *getEHLinkRegistrationType();
83 Type *getSEHRegistrationType();
84 Type *getCXXEHRegistrationType();
87 Module *TheModule = nullptr;
88 StructType *EHLinkRegistrationTy = nullptr;
89 StructType *CXXEHRegistrationTy = nullptr;
90 StructType *SEHRegistrationTy = nullptr;
91 Function *FrameRecover = nullptr;
92 Function *FrameAddress = nullptr;
93 Function *FrameEscape = nullptr;
96 EHPersonality Personality = EHPersonality::Unknown;
97 Function *PersonalityFn = nullptr;
99 /// The stack allocation containing all EH data, including the link in the
100 /// fs:00 chain and the current state.
101 AllocaInst *RegNode = nullptr;
103 /// Struct type of RegNode. Used for GEPing.
104 Type *RegNodeTy = nullptr;
106 /// The index of the state field of RegNode.
107 int StateFieldIndex = ~0U;
109 /// The linked list node subobject inside of RegNode.
110 Value *Link = nullptr;
114 FunctionPass *llvm::createX86WinEHStatePass() { return new WinEHStatePass(); }
116 char WinEHStatePass::ID = 0;
118 INITIALIZE_PASS(WinEHStatePass, "x86-winehstate",
119 "Insert stores for EH state numbers", false, false)
121 bool WinEHStatePass::doInitialization(Module &M) {
123 FrameEscape = Intrinsic::getDeclaration(TheModule, Intrinsic::localescape);
124 FrameRecover = Intrinsic::getDeclaration(TheModule, Intrinsic::localrecover);
125 FrameAddress = Intrinsic::getDeclaration(TheModule, Intrinsic::frameaddress);
129 bool WinEHStatePass::doFinalization(Module &M) {
130 assert(TheModule == &M);
132 EHLinkRegistrationTy = nullptr;
133 CXXEHRegistrationTy = nullptr;
134 SEHRegistrationTy = nullptr;
135 FrameEscape = nullptr;
136 FrameRecover = nullptr;
137 FrameAddress = nullptr;
141 void WinEHStatePass::getAnalysisUsage(AnalysisUsage &AU) const {
142 // This pass should only insert a stack allocation, memory accesses, and
144 AU.setPreservesCFG();
147 bool WinEHStatePass::runOnFunction(Function &F) {
148 // If this is an outlined handler, don't do anything. We'll do state insertion
149 // for it in the parent.
150 StringRef WinEHParentName =
151 F.getFnAttribute("wineh-parent").getValueAsString();
152 if (WinEHParentName != F.getName() && !WinEHParentName.empty())
155 // Check the personality. Do nothing if this is not an MSVC personality.
156 if (!F.hasPersonalityFn())
159 dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());
162 Personality = classifyEHPersonality(PersonalityFn);
163 if (!isMSVCEHPersonality(Personality))
166 // Disable frame pointer elimination in this function.
167 // FIXME: Do the nested handlers need to keep the parent ebp in ebp, or can we
168 // use an arbitrary register?
169 F.addFnAttr("no-frame-pointer-elim", "true");
171 emitExceptionRegistrationRecord(&F);
173 auto *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
174 // If MMI is null, create our own WinEHFuncInfo. This only happens in opt
176 std::unique_ptr<WinEHFuncInfo> FuncInfoPtr;
178 FuncInfoPtr.reset(new WinEHFuncInfo());
179 WinEHFuncInfo &FuncInfo =
180 *(MMI ? &MMI->getWinEHFuncInfo(&F) : FuncInfoPtr.get());
182 FuncInfo.EHRegNode = RegNode;
184 switch (Personality) {
185 default: llvm_unreachable("unexpected personality function");
186 case EHPersonality::MSVC_CXX:
187 addCXXStateStores(F, FuncInfo);
189 case EHPersonality::MSVC_X86SEH:
190 addSEHStateStores(F, FuncInfo);
194 // Reset per-function state.
195 PersonalityFn = nullptr;
196 Personality = EHPersonality::Unknown;
200 /// Get the common EH registration subobject:
201 /// typedef _EXCEPTION_DISPOSITION (*PEXCEPTION_ROUTINE)(
202 /// _EXCEPTION_RECORD *, void *, _CONTEXT *, void *);
203 /// struct EHRegistrationNode {
204 /// EHRegistrationNode *Next;
205 /// PEXCEPTION_ROUTINE Handler;
207 Type *WinEHStatePass::getEHLinkRegistrationType() {
208 if (EHLinkRegistrationTy)
209 return EHLinkRegistrationTy;
210 LLVMContext &Context = TheModule->getContext();
211 EHLinkRegistrationTy = StructType::create(Context, "EHRegistrationNode");
213 EHLinkRegistrationTy->getPointerTo(0), // EHRegistrationNode *Next
214 Type::getInt8PtrTy(Context) // EXCEPTION_DISPOSITION (*Handler)(...)
216 EHLinkRegistrationTy->setBody(FieldTys, false);
217 return EHLinkRegistrationTy;
220 /// The __CxxFrameHandler3 registration node:
221 /// struct CXXExceptionRegistration {
223 /// EHRegistrationNode SubRecord;
224 /// int32_t TryLevel;
226 Type *WinEHStatePass::getCXXEHRegistrationType() {
227 if (CXXEHRegistrationTy)
228 return CXXEHRegistrationTy;
229 LLVMContext &Context = TheModule->getContext();
231 Type::getInt8PtrTy(Context), // void *SavedESP
232 getEHLinkRegistrationType(), // EHRegistrationNode SubRecord
233 Type::getInt32Ty(Context) // int32_t TryLevel
235 CXXEHRegistrationTy =
236 StructType::create(FieldTys, "CXXExceptionRegistration");
237 return CXXEHRegistrationTy;
240 /// The _except_handler3/4 registration node:
241 /// struct EH4ExceptionRegistration {
243 /// _EXCEPTION_POINTERS *ExceptionPointers;
244 /// EHRegistrationNode SubRecord;
245 /// int32_t EncodedScopeTable;
246 /// int32_t TryLevel;
248 Type *WinEHStatePass::getSEHRegistrationType() {
249 if (SEHRegistrationTy)
250 return SEHRegistrationTy;
251 LLVMContext &Context = TheModule->getContext();
253 Type::getInt8PtrTy(Context), // void *SavedESP
254 Type::getInt8PtrTy(Context), // void *ExceptionPointers
255 getEHLinkRegistrationType(), // EHRegistrationNode SubRecord
256 Type::getInt32Ty(Context), // int32_t EncodedScopeTable
257 Type::getInt32Ty(Context) // int32_t TryLevel
259 SEHRegistrationTy = StructType::create(FieldTys, "SEHExceptionRegistration");
260 return SEHRegistrationTy;
263 // Emit an exception registration record. These are stack allocations with the
264 // common subobject of two pointers: the previous registration record (the old
265 // fs:00) and the personality function for the current frame. The data before
266 // and after that is personality function specific.
267 void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
268 assert(Personality == EHPersonality::MSVC_CXX ||
269 Personality == EHPersonality::MSVC_X86SEH);
271 StringRef PersonalityName = PersonalityFn->getName();
272 IRBuilder<> Builder(&F->getEntryBlock(), F->getEntryBlock().begin());
273 Type *Int8PtrType = Builder.getInt8PtrTy();
274 if (Personality == EHPersonality::MSVC_CXX) {
275 RegNodeTy = getCXXEHRegistrationType();
276 RegNode = Builder.CreateAlloca(RegNodeTy);
277 // SavedESP = llvm.stacksave()
278 Value *SP = Builder.CreateCall(
279 Intrinsic::getDeclaration(TheModule, Intrinsic::stacksave), {});
280 Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
283 insertStateNumberStore(RegNode, Builder.GetInsertPoint(), -1);
284 // Handler = __ehhandler$F
285 Function *Trampoline = generateLSDAInEAXThunk(F);
286 Link = Builder.CreateStructGEP(RegNodeTy, RegNode, 1);
287 linkExceptionRegistration(Builder, Trampoline);
288 } else if (Personality == EHPersonality::MSVC_X86SEH) {
289 // If _except_handler4 is in use, some additional guard checks and prologue
290 // stuff is required.
291 bool UseStackGuard = (PersonalityName == "_except_handler4");
292 RegNodeTy = getSEHRegistrationType();
293 RegNode = Builder.CreateAlloca(RegNodeTy);
294 // SavedESP = llvm.stacksave()
295 Value *SP = Builder.CreateCall(
296 Intrinsic::getDeclaration(TheModule, Intrinsic::stacksave), {});
297 Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
298 // TryLevel = -2 / -1
300 insertStateNumberStore(RegNode, Builder.GetInsertPoint(),
301 UseStackGuard ? -2 : -1);
302 // ScopeTable = llvm.x86.seh.lsda(F)
303 Value *FI8 = Builder.CreateBitCast(F, Int8PtrType);
304 Value *LSDA = Builder.CreateCall(
305 Intrinsic::getDeclaration(TheModule, Intrinsic::x86_seh_lsda), FI8);
306 Type *Int32Ty = Type::getInt32Ty(TheModule->getContext());
307 LSDA = Builder.CreatePtrToInt(LSDA, Int32Ty);
308 // If using _except_handler4, xor the address of the table with
309 // __security_cookie.
312 TheModule->getOrInsertGlobal("__security_cookie", Int32Ty);
313 Value *Val = Builder.CreateLoad(Int32Ty, Cookie);
314 LSDA = Builder.CreateXor(LSDA, Val);
316 Builder.CreateStore(LSDA, Builder.CreateStructGEP(RegNodeTy, RegNode, 3));
317 Link = Builder.CreateStructGEP(RegNodeTy, RegNode, 2);
318 linkExceptionRegistration(Builder, PersonalityFn);
320 llvm_unreachable("unexpected personality function");
323 // Insert an unlink before all returns.
324 for (BasicBlock &BB : *F) {
325 TerminatorInst *T = BB.getTerminator();
326 if (!isa<ReturnInst>(T))
328 Builder.SetInsertPoint(T);
329 unlinkExceptionRegistration(Builder);
333 Value *WinEHStatePass::emitEHLSDA(IRBuilder<> &Builder, Function *F) {
334 Value *FI8 = Builder.CreateBitCast(F, Type::getInt8PtrTy(F->getContext()));
335 return Builder.CreateCall(
336 Intrinsic::getDeclaration(TheModule, Intrinsic::x86_seh_lsda), FI8);
339 /// Generate a thunk that puts the LSDA of ParentFunc in EAX and then calls
340 /// PersonalityFn, forwarding the parameters passed to PEXCEPTION_ROUTINE:
341 /// typedef _EXCEPTION_DISPOSITION (*PEXCEPTION_ROUTINE)(
342 /// _EXCEPTION_RECORD *, void *, _CONTEXT *, void *);
343 /// We essentially want this code:
345 /// jmpl ___CxxFrameHandler3
346 Function *WinEHStatePass::generateLSDAInEAXThunk(Function *ParentFunc) {
347 LLVMContext &Context = ParentFunc->getContext();
348 Type *Int32Ty = Type::getInt32Ty(Context);
349 Type *Int8PtrType = Type::getInt8PtrTy(Context);
350 Type *ArgTys[5] = {Int8PtrType, Int8PtrType, Int8PtrType, Int8PtrType,
352 FunctionType *TrampolineTy =
353 FunctionType::get(Int32Ty, makeArrayRef(&ArgTys[0], 4),
355 FunctionType *TargetFuncTy =
356 FunctionType::get(Int32Ty, makeArrayRef(&ArgTys[0], 5),
358 Function *Trampoline =
359 Function::Create(TrampolineTy, GlobalValue::InternalLinkage,
360 Twine("__ehhandler$") + GlobalValue::getRealLinkageName(
361 ParentFunc->getName()),
363 BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", Trampoline);
364 IRBuilder<> Builder(EntryBB);
365 Value *LSDA = emitEHLSDA(Builder, ParentFunc);
366 Value *CastPersonality =
367 Builder.CreateBitCast(PersonalityFn, TargetFuncTy->getPointerTo());
368 auto AI = Trampoline->arg_begin();
369 Value *Args[5] = {LSDA, AI++, AI++, AI++, AI++};
370 CallInst *Call = Builder.CreateCall(CastPersonality, Args);
371 // Can't use musttail due to prototype mismatch, but we can use tail.
372 Call->setTailCall(true);
373 // Set inreg so we pass it in EAX.
374 Call->addAttribute(1, Attribute::InReg);
375 Builder.CreateRet(Call);
379 void WinEHStatePass::linkExceptionRegistration(IRBuilder<> &Builder,
381 // Emit the .safeseh directive for this function.
382 Handler->addFnAttr("safeseh");
384 Type *LinkTy = getEHLinkRegistrationType();
386 Value *HandlerI8 = Builder.CreateBitCast(Handler, Builder.getInt8PtrTy());
387 Builder.CreateStore(HandlerI8, Builder.CreateStructGEP(LinkTy, Link, 1));
390 Constant::getNullValue(LinkTy->getPointerTo()->getPointerTo(257));
391 Value *Next = Builder.CreateLoad(FSZero);
392 Builder.CreateStore(Next, Builder.CreateStructGEP(LinkTy, Link, 0));
394 Builder.CreateStore(Link, FSZero);
397 void WinEHStatePass::unlinkExceptionRegistration(IRBuilder<> &Builder) {
398 // Clone Link into the current BB for better address mode folding.
399 if (auto *GEP = dyn_cast<GetElementPtrInst>(Link)) {
400 GEP = cast<GetElementPtrInst>(GEP->clone());
404 Type *LinkTy = getEHLinkRegistrationType();
405 // [fs:00] = Link->Next
407 Builder.CreateLoad(Builder.CreateStructGEP(LinkTy, Link, 0));
409 Constant::getNullValue(LinkTy->getPointerTo()->getPointerTo(257));
410 Builder.CreateStore(Next, FSZero);
413 void WinEHStatePass::addCXXStateStores(Function &F, WinEHFuncInfo &FuncInfo) {
414 calculateWinCXXEHStateNumbers(&F, FuncInfo);
416 // The base state for the parent is -1.
417 addCXXStateStoresToFunclet(RegNode, FuncInfo, F, -1);
419 // Set up RegNodeEscapeIndex
420 int RegNodeEscapeIndex = escapeRegNode(F);
421 FuncInfo.EHRegNodeEscapeIndex = RegNodeEscapeIndex;
423 // Only insert stores in catch handlers.
425 ConstantExpr::getBitCast(&F, Type::getInt8PtrTy(TheModule->getContext()));
426 for (auto P : FuncInfo.HandlerBaseState) {
427 Function *Handler = const_cast<Function *>(P.first);
428 int BaseState = P.second;
429 IRBuilder<> Builder(&Handler->getEntryBlock(),
430 Handler->getEntryBlock().begin());
431 // FIXME: Find and reuse such a call if present.
432 Value *ParentFP = Builder.CreateCall(FrameAddress, {Builder.getInt32(1)});
433 Value *RecoveredRegNode = Builder.CreateCall(
434 FrameRecover, {FI8, ParentFP, Builder.getInt32(RegNodeEscapeIndex)});
436 Builder.CreateBitCast(RecoveredRegNode, RegNodeTy->getPointerTo(0));
437 addCXXStateStoresToFunclet(RecoveredRegNode, FuncInfo, *Handler, BaseState);
441 /// Escape RegNode so that we can access it from child handlers. Find the call
442 /// to localescape, if any, in the entry block and append RegNode to the list
444 int WinEHStatePass::escapeRegNode(Function &F) {
445 // Find the call to localescape and extract its arguments.
446 IntrinsicInst *EscapeCall = nullptr;
447 for (Instruction &I : F.getEntryBlock()) {
448 IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I);
449 if (II && II->getIntrinsicID() == Intrinsic::localescape) {
454 SmallVector<Value *, 8> Args;
456 auto Ops = EscapeCall->arg_operands();
457 Args.append(Ops.begin(), Ops.end());
459 Args.push_back(RegNode);
461 // Replace the call (if it exists) with new one. Otherwise, insert at the end
462 // of the entry block.
463 Instruction *InsertPt = EscapeCall;
465 InsertPt = F.getEntryBlock().getTerminator();
466 IRBuilder<> Builder(&F.getEntryBlock(), InsertPt);
467 Builder.CreateCall(FrameEscape, Args);
469 EscapeCall->eraseFromParent();
470 return Args.size() - 1;
473 void WinEHStatePass::addCXXStateStoresToFunclet(Value *ParentRegNode,
474 WinEHFuncInfo &FuncInfo,
475 Function &F, int BaseState) {
476 Function *RestoreFrame =
477 Intrinsic::getDeclaration(TheModule, Intrinsic::x86_seh_restoreframe);
478 // Iterate all the instructions and emit state number stores.
479 for (BasicBlock &BB : F) {
480 for (Instruction &I : BB) {
481 if (auto *CI = dyn_cast<CallInst>(&I)) {
482 // Possibly throwing call instructions have no actions to take after
483 // an unwind. Ensure they are in the -1 state.
484 if (CI->doesNotThrow())
486 insertStateNumberStore(ParentRegNode, CI, BaseState);
487 } else if (auto *II = dyn_cast<InvokeInst>(&I)) {
488 // Look up the state number of the landingpad this unwinds to.
489 Instruction *PadInst = II->getUnwindDest()->getFirstNonPHI();
490 // FIXME: Why does this assertion fail?
491 //assert(FuncInfo.EHPadStateMap.count(PadInst) && "EH Pad has no state!");
492 int State = FuncInfo.EHPadStateMap[PadInst];
493 insertStateNumberStore(ParentRegNode, II, State);
497 // Insert calls to llvm.x86.seh.restoreframe at catchret destinations.
498 if (auto *CR = dyn_cast<CatchReturnInst>(BB.getTerminator())) {
499 Instruction *Start = CR->getSuccessor()->begin();
500 assert(!isa<PHINode>(Start) &&
501 "winehprepare failed to demote phi after catchret");
502 if (match(Start, m_Intrinsic<Intrinsic::x86_seh_restoreframe>()))
504 IRBuilder<> Builder(Start);
505 Builder.CreateCall(RestoreFrame, {});
510 /// Assign every distinct landingpad a unique state number for SEH. Unlike C++
511 /// EH, we can use this very simple algorithm while C++ EH cannot because catch
512 /// handlers aren't outlined and the runtime doesn't have to figure out which
513 /// catch handler frame to unwind to.
514 /// FIXME: __finally blocks are outlined, so this approach may break down there.
515 void WinEHStatePass::addSEHStateStores(Function &F, WinEHFuncInfo &FuncInfo) {
516 // Remember and return the index that we used. We save it in WinEHFuncInfo so
517 // that we can lower llvm.x86.seh.recoverfp later in filter functions without
519 int RegNodeEscapeIndex = escapeRegNode(F);
520 FuncInfo.EHRegNodeEscapeIndex = RegNodeEscapeIndex;
522 // Iterate all the instructions and emit state number stores.
524 SmallPtrSet<BasicBlock *, 4> ExceptBlocks;
525 for (BasicBlock &BB : F) {
526 for (auto I = BB.begin(), E = BB.end(); I != E; ++I) {
527 if (auto *CI = dyn_cast<CallInst>(I)) {
528 auto *Intrin = dyn_cast<IntrinsicInst>(CI);
530 // Calls that "don't throw" are considered to be able to throw asynch
531 // exceptions, but intrinsics cannot.
534 insertStateNumberStore(RegNode, CI, -1);
535 } else if (auto *II = dyn_cast<InvokeInst>(I)) {
536 // Look up the state number of the landingpad this unwinds to.
537 LandingPadInst *LPI = II->getUnwindDest()->getLandingPadInst();
539 FuncInfo.EHPadStateMap.insert(std::make_pair(LPI, CurState));
540 auto Iter = InsertionPair.first;
541 int &State = Iter->second;
542 bool Inserted = InsertionPair.second;
544 // Each action consumes a state number.
545 auto *EHActions = cast<IntrinsicInst>(LPI->getNextNode());
546 SmallVector<std::unique_ptr<ActionHandler>, 4> ActionList;
547 parseEHActions(EHActions, ActionList);
548 assert(!ActionList.empty());
549 CurState += ActionList.size();
550 State += ActionList.size() - 1;
552 // Remember all the __except block targets.
553 for (auto &Handler : ActionList) {
554 if (auto *CH = dyn_cast<CatchHandler>(Handler.get())) {
555 auto *BA = cast<BlockAddress>(CH->getHandlerBlockOrFunc());
557 for (BasicBlock *Pred : predecessors(BA->getBasicBlock()))
558 assert(Pred->isLandingPad() &&
559 "WinEHPrepare failed to split block");
561 ExceptBlocks.insert(BA->getBasicBlock());
565 insertStateNumberStore(RegNode, II, State);
570 // Insert llvm.x86.seh.restoreframe() into each __except block.
571 Function *RestoreFrame =
572 Intrinsic::getDeclaration(TheModule, Intrinsic::x86_seh_restoreframe);
573 for (BasicBlock *ExceptBB : ExceptBlocks) {
574 IRBuilder<> Builder(ExceptBB->begin());
575 Builder.CreateCall(RestoreFrame, {});
579 void WinEHStatePass::insertStateNumberStore(Value *ParentRegNode,
580 Instruction *IP, int State) {
581 IRBuilder<> Builder(IP);
583 Builder.CreateStructGEP(RegNodeTy, ParentRegNode, StateFieldIndex);
584 Builder.CreateStore(Builder.getInt32(State), StateField);