Skip to content

Commit af1fbee

Browse files
committed
Thread ForUnwind_t into emitCleanupsForReturn.
Some "return" edges are for unwinding due to errors and some aren't. They'll need to be distinguished if we ever want to support throwing cleanups.
1 parent 1c99f31 commit af1fbee

File tree

8 files changed

+15
-12
lines changed

8 files changed

+15
-12
lines changed

lib/SILGen/Cleanup.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ void CleanupManager::emitBranchAndCleanups(JumpDest dest, SILLocation branchLoc,
138138
builder.createBranch(branchLoc, dest.getBlock(), args);
139139
}
140140

141-
void CleanupManager::emitCleanupsForReturn(CleanupLocation loc) {
141+
void CleanupManager::emitCleanupsForReturn(CleanupLocation loc,
142+
ForUnwind_t forUnwind) {
142143
SILGenBuilder &builder = SGF.getBuilder();
143144
assert(builder.hasValidInsertionPoint() && "Emitting return in invalid spot");
144145
(void)builder;
145-
emitCleanups(stack.stable_end(), loc, NotForUnwind, /*popCleanups=*/false);
146+
emitCleanups(stack.stable_end(), loc, forUnwind, /*popCleanups=*/false);
146147
}
147148

148149
/// Emit a new block that jumps to the specified location and runs necessary

lib/SILGen/Cleanup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class LLVM_LIBRARY_VISIBILITY CleanupManager {
173173

174174
/// emitCleanupsForReturn - Emit the top-level cleanups needed prior to a
175175
/// return from the function.
176-
void emitCleanupsForReturn(CleanupLocation loc);
176+
void emitCleanupsForReturn(CleanupLocation loc, ForUnwind_t forUnwind);
177177

178178
/// Emit a new block that jumps to the specified location and runs necessary
179179
/// cleanups based on its level. If there are no cleanups to run, this just

lib/SILGen/SILGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,8 @@ class SourceFileScope {
15081508
sgm.Types.getEmptyTupleType(), {}, {error});
15091509

15101510
// Signal an abnormal exit by returning 1.
1511-
SGF.Cleanups.emitCleanupsForReturn(CleanupLocation::get(moduleLoc));
1511+
SGF.Cleanups.emitCleanupsForReturn(CleanupLocation::get(moduleLoc),
1512+
IsForUnwind);
15121513
SGF.B.createBranch(returnLoc, returnBB, emitTopLevelReturnValue(1));
15131514
}
15141515

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4589,7 +4589,7 @@ SILValue SILGenFunction::emitApplyWithRethrow(SILLocation loc, SILValue fn,
45894589
B.createBuiltin(loc, SGM.getASTContext().getIdentifier("willThrow"),
45904590
SGM.Types.getEmptyTupleType(), {}, {error});
45914591

4592-
Cleanups.emitCleanupsForReturn(CleanupLocation::get(loc));
4592+
Cleanups.emitCleanupsForReturn(CleanupLocation::get(loc), IsForUnwind);
45934593
B.createThrow(loc, error);
45944594
}
45954595

lib/SILGen/SILGenConstructor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {
258258
SILGenSavedInsertionPoint savedIP(*this, failureBB,
259259
FunctionSection::Postmatter);
260260
failureExitBB = createBasicBlock();
261-
Cleanups.emitCleanupsForReturn(ctor);
261+
Cleanups.emitCleanupsForReturn(ctor, IsForUnwind);
262262
// Return nil.
263263
if (F.getConventions().hasIndirectSILResults()) {
264264
// Inject 'nil' into the indirect return.
@@ -658,7 +658,7 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
658658
failureExitArg = failureExitBB->createPHIArgument(
659659
resultLowering.getLoweredType(), ValueOwnershipKind::Owned);
660660

661-
Cleanups.emitCleanupsForReturn(ctor);
661+
Cleanups.emitCleanupsForReturn(ctor, IsForUnwind);
662662
SILValue nilResult =
663663
B.createEnum(loc, SILValue(), getASTContext().getOptionalNoneDecl(),
664664
resultLowering.getLoweredType());

lib/SILGen/SILGenEpilog.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ SILGenFunction::emitEpilogBB(SILLocation topLevel) {
186186
"emitting epilog in wrong scope");
187187

188188
auto cleanupLoc = CleanupLocation::get(topLevel);
189-
Cleanups.emitCleanupsForReturn(cleanupLoc);
189+
Cleanups.emitCleanupsForReturn(cleanupLoc, NotForUnwind);
190190

191191
// Build the return value. We don't do this if there are no direct
192192
// results; this can happen for void functions, but also happens when
@@ -297,7 +297,7 @@ void SILGenFunction::emitRethrowEpilog(SILLocation topLevel) {
297297
if (!prepareExtraEpilog(*this, ThrowDest, throwLoc, &exn))
298298
return;
299299

300-
Cleanups.emitCleanupsForReturn(ThrowDest.getCleanupLocation());
300+
Cleanups.emitCleanupsForReturn(ThrowDest.getCleanupLocation(), IsForUnwind);
301301

302302
B.createThrow(throwLoc, exn);
303303

@@ -309,7 +309,8 @@ void SILGenFunction::emitCoroutineUnwindEpilog(SILLocation topLevel) {
309309
if (!prepareExtraEpilog(*this, CoroutineUnwindDest, unwindLoc, nullptr))
310310
return;
311311

312-
Cleanups.emitCleanupsForReturn(CoroutineUnwindDest.getCleanupLocation());
312+
Cleanups.emitCleanupsForReturn(CoroutineUnwindDest.getCleanupLocation(),
313+
IsForUnwind);
313314

314315
B.createUnwind(unwindLoc);
315316

lib/SILGen/SILGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void SILGenFunction::emitArtificialTopLevel(ClassDecl *mainClass) {
552552
if (r->getType() != rType)
553553
r = B.createStruct(mainClass, rType, r);
554554

555-
Cleanups.emitCleanupsForReturn(mainClass);
555+
Cleanups.emitCleanupsForReturn(mainClass, NotForUnwind);
556556
B.createReturn(mainClass, r);
557557
return;
558558
}

lib/SILGen/SILGenMaterializeForSet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ void MaterializeForSetEmitter::emit(SILGenFunction &SGF) {
631631

632632
// Form the result and return.
633633
auto result = SGF.B.createTuple(loc, resultTupleTy, { address, callback });
634-
SGF.Cleanups.emitCleanupsForReturn(CleanupLocation::get(loc));
634+
SGF.Cleanups.emitCleanupsForReturn(CleanupLocation::get(loc), NotForUnwind);
635635
SGF.B.createReturn(loc, result);
636636
}
637637

0 commit comments

Comments
 (0)