Lines Matching +full:assert +full:- +full:falling +full:- +full:edge

1 //===--- CGCleanup.cpp - Bookkeeping and code emission for cleanups -------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
49 assert(rv.isAggregate()); in save()
57 /// Given a saved r-value produced by SaveRValue, perform the code
76 llvm_unreachable("bad saved r-value kind"); in restore()
79 /// Push an entry of the given size onto this protected-scope stack.
87 } else if (static_cast<size_t>(StartOfData - StartOfBuffer) < Size) { in allocate()
88 unsigned CurrentCapacity = EndOfBuffer - StartOfBuffer; in allocate()
89 unsigned UsedCapacity = CurrentCapacity - (StartOfData - StartOfBuffer); in allocate()
98 char *NewStartOfData = NewEndOfBuffer - UsedCapacity; in allocate()
106 assert(StartOfBuffer + Size <= StartOfData); in allocate()
107 StartOfData -= Size; in allocate()
119 if (!cleanup || !cleanup->isLifetimeMarker()) in containsOnlyLifetimeMarkers()
130 if (cleanup->isLifetimeMarker()) { in requiresLandingPad()
131 si = cleanup->getEnclosingEHScope(); in requiresLandingPad()
158 // Per C++ [except.terminate], it is implementation-defined whether none, in pushCleanup()
163 find(InnermostEHScope)->getKind() == EHScope::Terminate) in pushCleanup()
178 Scope->setLifetimeMarker(); in pushCleanup()
180 // With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup in pushCleanup()
184 // consistent with MSVC's behavior, except in the presence of -EHa. in pushCleanup()
186 if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker && in pushCleanup()
187 CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest()) in pushCleanup()
188 CGF->EmitSehCppScopeBegin(); in pushCleanup()
190 return Scope->getCleanupBuffer(); in pushCleanup()
194 assert(!empty() && "popping exception stack when not empty"); in popCleanup()
196 assert(isa<EHCleanupScope>(*begin())); in popCleanup()
205 // Check whether we can shrink the branch-fixups stack. in popCleanup()
219 assert(getInnermostEHScope() == stable_end()); in pushFilter()
227 assert(!empty() && "popping exception stack when not empty"); in popFilter()
257 assert(hasNormalCleanups()); in popNullFixups()
261 assert(BranchFixups.size() >= MinSize && "fixup stack out of order"); in popNullFixups()
286 assert(!cleanup.hasActiveFlag() && "cleanup already has active flag?"); in initFullExprCleanupWithFlag()
299 store->setAlignment(addr.getAlignment().getAsAlign()); in createStoreInstBefore()
335 Fixup.InitialBranch->setSuccessor(0, CleanupEntry); in ResolveAllBranchFixups()
342 Switch->addCase(CGF.Builder.getInt32(Fixup.DestinationIndex), in ResolveAllBranchFixups()
349 /// Transitions the terminator of the given exit-block of a cleanup to
355 llvm::Instruction *Term = Block->getTerminator(); in TransitionToCleanupSwitch()
356 assert(Term && "can't transition block without terminator"); in TransitionToCleanupSwitch()
359 assert(Br->isUnconditional()); in TransitionToCleanupSwitch()
363 llvm::SwitchInst::Create(Load, Br->getSuccessor(0), 4, Block); in TransitionToCleanupSwitch()
364 Br->eraseFromParent(); in TransitionToCleanupSwitch()
372 assert(Block && "resolving a null target block"); in ResolveBranchFixups()
375 assert(EHStack.hasNormalCleanups() && in ResolveBranchFixups()
402 Switch->addCase(Builder.getInt32(Fixup.DestinationIndex), Block); in ResolveBranchFixups()
413 assert(Old.isValid()); in PopCleanupBlocks()
445 if (AI && AI->isStaticAlloca()) in PopCleanupBlocks()
449 CreateDefaultAlignTempAlloca(Inst->getType(), "tmp.exprcleanup"); in PopCleanupBlocks()
454 InsertBefore = Invoke->getNormalDest()->getFirstInsertionPt(); in PopCleanupBlocks()
456 InsertBefore = std::next(Inst->getIterator()); in PopCleanupBlocks()
465 /// cleanups from the given savepoint in the lifetime-extended cleanups stack.
475 assert((I % alignof(LifetimeExtendedCleanupHeader) == 0) && in PopCleanupBlocks()
500 assert(Scope.isNormalCleanup()); in CreateNormalEntry()
516 llvm::BasicBlock *Pred = Entry->getSinglePredecessor(); in SimplifyCleanupEntry()
519 llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Pred->getTerminator()); in SimplifyCleanupEntry()
520 if (!Br || Br->isConditional()) return Entry; in SimplifyCleanupEntry()
521 assert(Br->getSuccessor(0) == Entry); in SimplifyCleanupEntry()
527 assert(!WasInsertBlock || CGF.Builder.GetInsertPoint() == Entry->end()); in SimplifyCleanupEntry()
530 Br->eraseFromParent(); in SimplifyCleanupEntry()
534 Entry->replaceAllUsesWith(Pred); in SimplifyCleanupEntry()
537 Pred->splice(Pred->end(), Entry); in SimplifyCleanupEntry()
540 Entry->eraseFromParent(); in SimplifyCleanupEntry()
565 Fn->Emit(CGF, flags); in EmitCleanup()
566 assert(CGF.HaveInsertPoint() && "cleanup ended with no insertion point?"); in EmitCleanup()
578 llvm::Instruction *Term = Exit->getTerminator(); in ForwardPrebranchedFallthrough()
581 assert(Br->isUnconditional() && Br->getSuccessor(0) == From); in ForwardPrebranchedFallthrough()
582 Br->setSuccessor(0, To); in ForwardPrebranchedFallthrough()
585 for (unsigned I = 0, E = Switch->getNumSuccessors(); I != E; ++I) in ForwardPrebranchedFallthrough()
586 if (Switch->getSuccessor(I) == From) in ForwardPrebranchedFallthrough()
587 Switch->setSuccessor(I, To); in ForwardPrebranchedFallthrough()
605 i = entry->use_begin(), e = entry->use_end(); i != e; ) { in destroyOptimisticNormalEntry()
613 if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) { in destroyOptimisticNormalEntry()
615 llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(), si); in destroyOptimisticNormalEntry()
617 // The switch operand is a load from the cleanup-dest alloca. in destroyOptimisticNormalEntry()
618 llvm::LoadInst *condition = cast<llvm::LoadInst>(si->getCondition()); in destroyOptimisticNormalEntry()
621 si->eraseFromParent(); in destroyOptimisticNormalEntry()
624 assert(condition->getOperand(0) == CGF.NormalCleanupDest.getPointer()); in destroyOptimisticNormalEntry()
625 assert(condition->use_empty()); in destroyOptimisticNormalEntry()
626 condition->eraseFromParent(); in destroyOptimisticNormalEntry()
630 assert(entry->use_empty()); in destroyOptimisticNormalEntry()
639 assert(!EHStack.empty() && "cleanup stack is empty!"); in PopCleanupBlock()
640 assert(isa<EHCleanupScope>(*EHStack.begin()) && "top not a cleanup!"); in PopCleanupBlock()
642 assert(Scope.getFixupDepth() <= EHStack.getNumBranchFixups()); in PopCleanupBlock()
662 assert(Scope.hasEHBranches() == (EHEntry != nullptr)); in PopCleanupBlock()
668 // - whether there are branch fix-ups through this cleanup in PopCleanupBlock()
672 // - whether there are branch-throughs or branch-afters in PopCleanupBlock()
675 // - whether there's a fallthrough in PopCleanupBlock()
680 // Branch-through fall-throughs leave the insertion point set to the in PopCleanupBlock()
685 (FallthroughSource && FallthroughSource->getTerminator()); in PopCleanupBlock()
690 assert(!Scope.isNormalCleanup() || !HasPrebranchedFallthrough || in PopCleanupBlock()
692 FallthroughSource->getTerminator()->getSuccessor(0) in PopCleanupBlock()
706 // fallthrough and add tests. Otherwise delete this and assert against it. in PopCleanupBlock()
707 assert(!IsActive); in PopCleanupBlock()
722 prebranchDest = createBasicBlock("forwarded-prebranch"); in PopCleanupBlock()
727 assert(normalEntry && !normalEntry->use_empty()); in PopCleanupBlock()
737 assert(EHStack.getNumBranchFixups() == 0 || in PopCleanupBlock()
771 // Under -EHa, invoke seh.scope.end() to mark scope end before dtor in PopCleanupBlock()
775 // Mark CPP scope end for passed-by-value Arg temp in PopCleanupBlock()
797 // mark SEH scope end for fall-through flow in PopCleanupBlock()
817 // I. Set up the fallthrough edge in. in PopCleanupBlock()
822 // destination index. For fall-throughs this is always zero. in PopCleanupBlock()
830 assert(!IsActive && "source without fallthrough for active cleanup"); in PopCleanupBlock()
853 // Compute the branch-through dest if we need it: in PopCleanupBlock()
854 // - if there are branch-throughs threaded through the scope in PopCleanupBlock()
855 // - if fall-through is a branch-through in PopCleanupBlock()
856 // - if there are fixups that will be optimistically forwarded in PopCleanupBlock()
862 assert(HasEnclosingCleanups); in PopCleanupBlock()
870 // If there's exactly one branch-after and no other threads, in PopCleanupBlock()
873 // abnormal termination. (SEH: Except _leave and fall-through at in PopCleanupBlock()
879 assert(!BranchThroughDest || !IsActive); in PopCleanupBlock()
884 if (NormalCleanupDestSlot->hasOneUse()) { in PopCleanupBlock()
885 NormalCleanupDestSlot->user_back()->eraseFromParent(); in PopCleanupBlock()
886 NormalCleanupDestSlot->eraseFromParent(); in PopCleanupBlock()
893 // Build a switch-out if we need it: in PopCleanupBlock()
894 // - if there are branch-afters threaded through the scope in PopCleanupBlock()
895 // - if fall-through is a branch-after in PopCleanupBlock()
896 // - if there are fixups that have nowhere left to go and in PopCleanupBlock()
905 // TODO: base this on the number of branch-afters and fixups in PopCleanupBlock()
919 // Branch-after fallthrough. in PopCleanupBlock()
923 Switch->addCase(Builder.getInt32(0), FallthroughDest); in PopCleanupBlock()
927 Switch->addCase(Scope.getBranchAfterIndex(I), in PopCleanupBlock()
936 // We should always have a branch-through destination in this case. in PopCleanupBlock()
937 assert(BranchThroughDest); in PopCleanupBlock()
944 assert(EHStack.hasNormalCleanups() == HasEnclosingCleanups); in PopCleanupBlock()
951 InstsToAppend[I]->insertInto(NormalExit, NormalExit->end()); in PopCleanupBlock()
953 // Optimistically hope that any fixups will continue falling through. in PopCleanupBlock()
962 Fixup.InitialBranch->setSuccessor(0, NormalEntry); in PopCleanupBlock()
967 // V. Set up the fallthrough edge out. in PopCleanupBlock()
973 // Non-prebranched fallthrough doesn't need to be forwarded. in PopCleanupBlock()
975 assert(!IsActive); in PopCleanupBlock()
982 assert(!FallthroughIsBranchThrough); in PopCleanupBlock()
998 // This might invalidate (non-IR) pointers to NormalEntry. in PopCleanupBlock()
1013 assert(EHStack.hasNormalCleanups() || EHStack.getNumBranchFixups() == 0); in PopCleanupBlock()
1038 // Non-MSVC personalities need to terminate when an EH cleanup throws. in PopCleanupBlock()
1068 /// isObviouslyBranchWithoutCleanups - Return true if a branch to the
1072 assert(Dest.getScopeDepth().encloses(EHStack.stable_begin()) in isObviouslyBranchWithoutCleanups()
1092 /// the current cleanup-protected scope. The target scope may not yet
1095 /// As a side-effect, this method clears the insertion point.
1097 assert(Dest.getScopeDepth().encloses(EHStack.stable_begin()) in EmitBranchThroughCleanup()
1142 BI->setSuccessor(0, CreateNormalEntry(*this, Scope)); in EmitBranchThroughCleanup()
1151 assert(Scope.isNormalCleanup()); in EmitBranchThroughCleanup()
1175 if (EHStack.find(cleanup)->hasEHBranches()) in IsUsedAsEHCleanup()
1181 assert(cleanup.strictlyEncloses(i)); in IsUsedAsEHCleanup()
1202 /// extra uses *after* the change-over point.
1219 // - as a normal cleanup in SetupCleanupBlockActivation()
1225 // - as an EH cleanup in SetupCleanupBlockActivation()
1244 assert(dominatingIP && "no existing variable and no dominating IP!"); in SetupCleanupBlockActivation()
1265 assert(C != EHStack.stable_end() && "activating bottom of stack?"); in ActivateCleanupBlock()
1267 assert(!Scope.isActive() && "double activation"); in ActivateCleanupBlock()
1277 assert(C != EHStack.stable_end() && "deactivating bottom of stack?"); in DeactivateCleanupBlock()
1279 assert(Scope.isActive() && "double deactivation"); in DeactivateCleanupBlock()
1316 assert(CGF.Builder.GetInsertBlock() && InvokeDest); in EmitSehScope()
1327 // Invoke a llvm.seh.scope.begin at the beginning of a CPP scope for -EHa
1329 assert(getLangOpts().EHAsynch); in EmitSehCppScopeBegin()
1337 // Invoke a llvm.seh.scope.end at the end of a CPP scope for -EHa
1340 assert(getLangOpts().EHAsynch); in EmitSehCppScopeEnd()
1348 // Invoke a llvm.seh.try.begin at the beginning of a SEH scope for -EHa
1350 assert(getLangOpts().EHAsynch); in EmitSehTryScopeBegin()
1358 // Invoke a llvm.seh.try.end at the end of a SEH scope for -EHa
1360 assert(getLangOpts().EHAsynch); in EmitSehTryScopeEnd()