Skip to content

Commit 4240d01

Browse files
authored
Merge pull request #7829 from gottesmm/checked_cast_br_1
2 parents 2d7491e + 455c126 commit 4240d01

File tree

13 files changed

+574
-125
lines changed

13 files changed

+574
-125
lines changed

lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,12 @@ void SILInstruction::verifyOperandOwnership() const {
17861786
// If SILOwnership is not enabled, do not perform verification.
17871787
if (!getModule().getOptions().EnableSILOwnership)
17881788
return;
1789+
1790+
// If the given function has unqualified ownership, there is nothing to
1791+
// verify.
1792+
if (getFunction()->hasUnqualifiedOwnership())
1793+
return;
1794+
17891795
// If we are testing the verifier, bail so we only print errors once when
17901796
// performing a full verification, instead of additionally in the SILBuilder.
17911797
if (IsSILOwnershipVerifierTestingEnabled)
@@ -1809,6 +1815,21 @@ void SILInstruction::verifyOperandOwnership() const {
18091815
void SILValue::verifyOwnership(SILModule &Mod,
18101816
TransitivelyUnreachableBlocksInfo *TUB) const {
18111817
#ifndef NDEBUG
1818+
// If we are SILUndef, just bail. SILUndef can pair with anything. Any uses of
1819+
// the SILUndef will make sure that the matching checks out.
1820+
if (isa<SILUndef>(*this))
1821+
return;
1822+
1823+
// Since we do not have SILUndef, we now know that getFunction() should return
1824+
// a real function. Assert in case this assumption is no longer true.
1825+
SILFunction *F = (*this)->getFunction();
1826+
assert(F && "Instructions and arguments should have a function");
1827+
1828+
// If the given function has unqualified ownership, there is nothing further
1829+
// to verify.
1830+
if (F->hasUnqualifiedOwnership())
1831+
return;
1832+
18121833
if (TUB) {
18131834
SILValueOwnershipChecker(Mod, *TUB, *this).check();
18141835
} else {

lib/SIL/SILVerifier.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,8 +2564,20 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
25642564
CBI->getCastType(),
25652565
"success dest block argument of checked_cast_br must match type of "
25662566
"cast");
2567-
require(CBI->getFailureBB()->args_empty(),
2568-
"failure dest of checked_cast_br must take no arguments");
2567+
require(F.hasQualifiedOwnership() || CBI->getFailureBB()->args_empty(),
2568+
"failure dest of checked_cast_br in unqualified ownership sil must "
2569+
"take no arguments");
2570+
#if 0
2571+
require(F.hasUnqualifiedOwnership() ||
2572+
CBI->getFailureBB()->args_size() == 1,
2573+
"failure dest of checked_cast_br must take one argument in "
2574+
"ownership qualified sil");
2575+
require(F.hasUnqualifiedOwnership() ||
2576+
CBI->getFailureBB()->args_begin()[0]->getType() ==
2577+
CBI->getOperand()->getType(),
2578+
"failure dest block argument must match type of original type in "
2579+
"ownership qualified sil");
2580+
#endif
25692581
}
25702582

25712583
void checkCheckedCastAddrBranchInst(CheckedCastAddrBranchInst *CCABI) {

lib/SILGen/SILGenBuilder.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,25 @@ ManagedValue SILGenBuilder::createEnum(SILLocation loc, ManagedValue payload,
489489
return gen.emitManagedRValueWithCleanup(result);
490490
}
491491

492+
ManagedValue SILGenBuilder::createUnconditionalCheckedCastOpaque(
493+
SILLocation loc, ManagedValue operand, SILType type) {
494+
SILValue result = SILBuilder::createUnconditionalCheckedCastOpaque(
495+
loc, operand.forward(gen), type);
496+
return gen.emitManagedRValueWithCleanup(result);
497+
}
498+
499+
ManagedValue SILGenBuilder::createUnconditionalCheckedCast(SILLocation loc,
500+
ManagedValue operand,
501+
SILType type) {
502+
SILValue result = SILBuilder::createUnconditionalCheckedCast(
503+
loc, operand.forward(gen), type);
504+
return gen.emitManagedRValueWithCleanup(result);
505+
}
506+
507+
void SILGenBuilder::createCheckedCastBranch(SILLocation loc, bool isExact,
508+
ManagedValue operand, SILType type,
509+
SILBasicBlock *trueBlock,
510+
SILBasicBlock *falseBlock) {
511+
SILBuilder::createCheckedCastBranch(loc, isExact, operand.forward(gen), type,
512+
trueBlock, falseBlock);
513+
}

lib/SILGen/SILGenBuilder.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,21 @@ class SILGenBuilder : public SILBuilder {
211211
ManagedValue formalAccessBufferForExpr(
212212
SILLocation loc, SILType ty, const TypeLowering &lowering,
213213
SGFContext context, std::function<void(SILValue)> rvalueEmitter);
214+
215+
using SILBuilder::createUnconditionalCheckedCastOpaque;
216+
ManagedValue createUnconditionalCheckedCastOpaque(SILLocation loc,
217+
ManagedValue operand,
218+
SILType type);
219+
using SILBuilder::createUnconditionalCheckedCast;
220+
ManagedValue createUnconditionalCheckedCast(SILLocation loc,
221+
ManagedValue operand,
222+
SILType type);
223+
224+
using SILBuilder::createCheckedCastBranch;
225+
void createCheckedCastBranch(SILLocation loc, bool isExact,
226+
ManagedValue operand, SILType type,
227+
SILBasicBlock *trueBlock,
228+
SILBasicBlock *falseBlock);
214229
};
215230

216231
} // namespace Lowering

0 commit comments

Comments
 (0)