@@ -2969,35 +2969,34 @@ SILValue LifetimeChecker::handleConditionalInitAssign() {
29692969
29702970 // Create the control variable as the first instruction in the function (so
29712971 // that it is easy to destroy the stack location.
2972- SILBuilder B (TheMemory.getFunctionEntryPoint ());
2973- B.setCurrentDebugScope (TheMemory.getFunction ().getDebugScope ());
29742972 SILType IVType =
29752973 SILType::getBuiltinIntegerType (NumMemoryElements, Module.getASTContext ());
29762974 // Use an empty location for the alloc_stack. If Loc is variable declaration
29772975 // the alloc_stack would look like the storage of that variable.
2978- auto *ControlVariableBox = B.createAllocStack (
2979- RegularLocation::getAutoGeneratedLocation (), IVType);
2976+ auto *ControlVariableBox =
2977+ SILBuilderWithScope (TheMemory.getFunctionEntryPoint ())
2978+ .createAllocStack (RegularLocation::getAutoGeneratedLocation (),
2979+ IVType);
29802980
29812981 // Find all the return blocks in the function, inserting a dealloc_stack
29822982 // before the return.
29832983 for (auto &BB : TheMemory.getFunction ()) {
29842984 auto *Term = BB.getTerminator ();
29852985 if (Term->isFunctionExiting ()) {
2986- B.setInsertionPoint (Term);
2987- B.setCurrentDebugScope (Term->getDebugScope ());
2988- B.createDeallocStack (Loc, ControlVariableBox);
2986+ SILBuilderWithScope (Term).createDeallocStack (Loc, ControlVariableBox);
29892987 }
29902988 }
29912989
29922990 // Before the memory allocation, store zero in the control variable.
2993- auto *InsertPoint =
2994- &*std::next (TheMemory.getUninitializedValue ()->getIterator ());
2995- B.setInsertionPoint (InsertPoint);
2996- B.setCurrentDebugScope (InsertPoint->getDebugScope ());
29972991 SILValue ControlVariableAddr = ControlVariableBox;
2998- auto Zero = B.createIntegerLiteral (Loc, IVType, 0 );
2999- B.createStore (Loc, Zero, ControlVariableAddr,
3000- StoreOwnershipQualifier::Trivial);
2992+ {
2993+ auto *InsertPoint =
2994+ &*std::next (TheMemory.getUninitializedValue ()->getIterator ());
2995+ SILBuilderWithScope B (InsertPoint);
2996+ auto Zero = B.createIntegerLiteral (Loc, IVType, 0 );
2997+ B.createStore (Loc, Zero, ControlVariableAddr,
2998+ StoreOwnershipQualifier::Trivial);
2999+ }
30013000
30023001 Identifier OrFn;
30033002
@@ -3021,7 +3020,7 @@ SILValue LifetimeChecker::handleConditionalInitAssign() {
30213020 Use.onlyTouchesTrivialElements (TheMemory))
30223021 continue ;
30233022
3024- B. setInsertionPoint (Use.Inst );
3023+ SILBuilderWithScope B (Use.Inst );
30253024
30263025 // Only full initializations make something live. inout uses, escapes, and
30273026 // assignments only happen when some kind of init made the element live.
@@ -3110,7 +3109,7 @@ SILValue LifetimeChecker::handleConditionalInitAssign() {
31103109 if (HasConditionalSelfInitialized) {
31113110 for (auto *I : StoresToSelf) {
31123111 auto *bb = I->getParent ();
3113- B. setInsertionPoint (bb->begin ());
3112+ SILBuilderWithScope B (bb->begin ());
31143113
31153114 // Set the most significant bit.
31163115 APInt Bitmask = APInt::getHighBitsSet (NumMemoryElements, 1 );
0 commit comments