Skip to content

Commit 5684c32

Browse files
authored
Merge pull request #69654 from DougGregor/throw-addr-fixes
[Typed throws] Handle `throw_addr` in the same places as `throw`.
2 parents 47a6d67 + 118db28 commit 5684c32

File tree

8 files changed

+13
-10
lines changed

8 files changed

+13
-10
lines changed

include/swift/SIL/ApplySite.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ class FullApplySite : public ApplySite {
746746
bool isIndirectErrorResultOperand(const Operand &op) const {
747747
return isArgumentOperand(op)
748748
&& (getCalleeArgIndex(op) >= getNumIndirectSILResults())
749-
&& (getCalleeArgIndex(op) < getNumIndirectSILErrorResults());
749+
&& (getCalleeArgIndex(op) < getNumIndirectSILResults() + getNumIndirectSILErrorResults());
750750
}
751751

752752
static FullApplySite getFromOpaqueValue(void *p) { return FullApplySite(p); }

include/swift/SIL/SILFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ class SILFunction
14031403
return std::find_if(begin(), end(),
14041404
[](const SILBasicBlock &BB) -> bool {
14051405
const TermInst *TI = BB.getTerminator();
1406-
return isa<ThrowInst>(TI);
1406+
return isa<ThrowInst>(TI) || isa<ThrowAddrInst>(TI);
14071407
});
14081408
}
14091409

@@ -1413,7 +1413,7 @@ class SILFunction
14131413
return std::find_if(begin(), end(),
14141414
[](const SILBasicBlock &BB) -> bool {
14151415
const TermInst *TI = BB.getTerminator();
1416-
return isa<ThrowInst>(TI);
1416+
return isa<ThrowInst>(TI) || isa<ThrowAddrInst>(TI);
14171417
});
14181418
}
14191419

include/swift/SILOptimizer/Analysis/EpilogueARCAnalysis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ class EpilogueARCContext {
9999
return BB->getTerminator()->isFunctionExiting();
100100

101101
return BB->getTerminator()->isFunctionExiting() &&
102-
BB->getTerminator()->getTermKind() != TermKind::ThrowInst;
102+
BB->getTerminator()->getTermKind() != TermKind::ThrowInst &&
103+
BB->getTerminator()->getTermKind() != TermKind::ThrowAddrInst;
103104
}
104105

105106
/// Return true if this is a function exit block.

include/swift/SILOptimizer/Utils/PerformanceInlinerUtils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ class ShortestPathAnalysis {
456456

457457
if (isa<ReturnInst>(BB.getTerminator()))
458458
BBInfo->getDistances(0).DistToExit = Length;
459-
else if (isa<ThrowInst>(BB.getTerminator()))
459+
else if (isa<ThrowInst>(BB.getTerminator()) ||
460+
isa<ThrowAddrInst>(BB.getTerminator()))
460461
BBInfo->getDistances(0).DistToExit = Length + ColdBlockLength;
461462
}
462463
// Compute the distances for all loops in the function.

lib/SIL/IR/SILInstruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ bool SILInstruction::isTriviallyDuplicatable() const {
14061406
if (MI->getMember().isForeign)
14071407
return false;
14081408
}
1409-
if (isa<ThrowInst>(this))
1409+
if (isa<ThrowInst>(this) || isa<ThrowAddrInst>(this))
14101410
return false;
14111411

14121412
// BeginAccess defines the access scope entry point. All associated EndAccess

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6265,7 +6265,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
62656265
return true;
62666266
else if (isa<ReturnInst>(StartBlock->getTerminator()))
62676267
return false;
6268-
else if (isa<ThrowInst>(StartBlock->getTerminator()))
6268+
else if (isa<ThrowInst>(StartBlock->getTerminator()) ||
6269+
isa<ThrowAddrInst>(StartBlock->getTerminator()))
62696270
return false;
62706271

62716272
// Recursively check all successors.

lib/SILOptimizer/Transforms/ARCCodeMotion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ class RetainCodeMotionContext : public CodeMotionContext {
330330
// end, this function is called many times.
331331
//
332332
// These terminator instructions block.
333-
if (isa<ReturnInst>(II) || isa<ThrowInst>(II) || isa<UnwindInst>(II) ||
334-
isa<UnreachableInst>(II))
333+
if (isa<ReturnInst>(II) || isa<ThrowInst>(II) || isa<ThrowAddrInst>(II) ||
334+
isa<UnwindInst>(II) || isa<UnreachableInst>(II))
335335
return true;
336336
// Identical RC root blocks code motion, we will be able to move this retain
337337
// further once we move the blocking retain.

lib/SILOptimizer/Utils/LoopUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ bool swift::canDuplicateLoopInstruction(SILLoop *L, SILInstruction *I) {
275275
return true;
276276
}
277277

278-
if (isa<ThrowInst>(I))
278+
if (isa<ThrowInst>(I) || isa<ThrowAddrInst>(I))
279279
return false;
280280

281281
// The entire access must be within the loop.

0 commit comments

Comments
 (0)