Skip to content

Commit 4985746

Browse files
committed
SIL verifier: Fix polarity of consuming check through (unchecked_addr_cast (open_existential_addr)).
This was looking for a single non-consuming use instead of checking for the absence of any consuming uses, leading to false-positives when there were multiple non-consuming uses. Fixes rdar://problem/44116763.
1 parent 6f3b618 commit 4985746

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,35 +2840,23 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
28402840
case SILInstructionKind::DestroyAddrInst:
28412841
return true;
28422842
case SILInstructionKind::UncheckedAddrCastInst: {
2843-
// Don't be too conservative here, we have a new case:
2844-
// sil-combine producing a new code pattern for devirtualizer
2845-
// open_existential_addr immutable_access -> witness_method
2846-
// witness_method gets transformed into unchecked_addr_cast
2847-
// we are "OK" If one of the new users is an non-consuming apply
2848-
// we are also "OK" if we have a single non-consuming user
28492843
auto isCastToNonConsuming = [=](UncheckedAddrCastInst *I) -> bool {
28502844
for (auto *use : I->getUses()) {
28512845
auto *inst = use->getUser();
28522846
switch (inst->getKind()) {
28532847
case SILInstructionKind::ApplyInst:
28542848
case SILInstructionKind::TryApplyInst:
28552849
case SILInstructionKind::PartialApplyInst:
2856-
if (!isConsumingOrMutatingApplyUse(use))
2857-
return true;
2858-
break;
2859-
case SILInstructionKind::StructElementAddrInst:
2860-
case SILInstructionKind::LoadInst:
2861-
case SILInstructionKind::DebugValueAddrInst:
2862-
if (I->hasOneUse())
2863-
return true;
2864-
break;
2850+
if (isConsumingOrMutatingApplyUse(use))
2851+
return false;
2852+
continue;
28652853
default:
2866-
break;
2854+
continue;
28672855
}
28682856
}
2869-
return false;
2857+
return true;
28702858
};
2871-
if (isCastToNonConsuming(dyn_cast<UncheckedAddrCastInst>(inst))) {
2859+
if (isCastToNonConsuming(cast<UncheckedAddrCastInst>(inst))) {
28722860
break;
28732861
}
28742862
return true;

0 commit comments

Comments
 (0)