3535#include " swift/SIL/DebugUtils.h"
3636#include " swift/SIL/Dominance.h"
3737#include " swift/SIL/DynamicCasts.h"
38+ #include " swift/SIL/InstructionUtils.h"
3839#include " swift/SIL/MemAccessUtils.h"
3940#include " swift/SIL/OwnershipLiveness.h"
4041#include " swift/SIL/OwnershipUtils.h"
@@ -572,6 +573,11 @@ void verifyKeyPathComponent(SILModule &M,
572573// / open_existential_addr. We should expand it as needed.
573574struct ImmutableAddressUseVerifier {
574575 SmallVector<Operand *, 32 > worklist;
576+ bool ignoreDestroys;
577+ bool defaultIsMutating;
578+
579+ ImmutableAddressUseVerifier (bool ignoreDestroys = false , bool defaultIsMutating = false )
580+ : ignoreDestroys(ignoreDestroys), defaultIsMutating(defaultIsMutating) {}
575581
576582 bool isConsumingOrMutatingArgumentConvention (SILArgumentConvention conv) {
577583 switch (conv) {
@@ -704,10 +710,9 @@ struct ImmutableAddressUseVerifier {
704710 }
705711 }
706712
707- // Otherwise this is a builtin that we are not expecting to see, so bail
708- // and assert.
709- llvm::errs () << " Unhandled, unexpected builtin instruction: " << *inst;
710- llvm_unreachable (" invoking standard assertion failure" );
713+ // Otherwise this is a builtin that we are not expecting to see.
714+ if (defaultIsMutating)
715+ return true ;
711716 break ;
712717 }
713718 case SILInstructionKind::MarkDependenceInst:
@@ -775,7 +780,9 @@ struct ImmutableAddressUseVerifier {
775780 else
776781 break ;
777782 case SILInstructionKind::DestroyAddrInst:
778- return true ;
783+ if (!ignoreDestroys)
784+ return true ;
785+ break ;
779786 case SILInstructionKind::UpcastInst:
780787 case SILInstructionKind::UncheckedAddrCastInst: {
781788 if (isAddrCastToNonConsuming (cast<SingleValueInstruction>(inst))) {
@@ -841,9 +848,7 @@ struct ImmutableAddressUseVerifier {
841848 }
842849 break ;
843850 }
844- llvm::errs () << " Unhandled, unexpected instruction: " << *inst;
845- llvm_unreachable (" invoking standard assertion failure" );
846- break ;
851+ return true ;
847852 }
848853 case SILInstructionKind::TuplePackElementAddrInst: {
849854 if (&cast<TuplePackElementAddrInst>(inst)->getOperandRef (
@@ -865,8 +870,8 @@ struct ImmutableAddressUseVerifier {
865870 return false ;
866871 }
867872 default :
868- llvm::errs () << " Unhandled, unexpected instruction: " << *inst;
869- llvm_unreachable ( " invoking standard assertion failure " ) ;
873+ if (defaultIsMutating)
874+ return true ;
870875 break ;
871876 }
872877 }
@@ -7385,6 +7390,11 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
73857390#undef require
73867391#undef requireObjectType
73877392
7393+ bool swift::isIndirectArgumentMutated (SILFunctionArgument *arg, bool ignoreDestroys,
7394+ bool defaultIsMutating) {
7395+ return ImmutableAddressUseVerifier (ignoreDestroys, defaultIsMutating).isMutatingOrConsuming (arg);
7396+ }
7397+
73887398// ===----------------------------------------------------------------------===//
73897399// Out of Line Verifier Run Functions
73907400// ===----------------------------------------------------------------------===//
0 commit comments