@@ -89,7 +89,7 @@ class SILValueOwnershipChecker {
89
89
90
90
// / The builder that the checker uses to emit error messages, crash if asked
91
91
// / for, or supply back interesting info to the caller.
92
- LinearLifetimeChecker::ErrorBuilder errorBuilder;
92
+ LinearLifetimeChecker::ErrorBuilder & errorBuilder;
93
93
94
94
// / The list of lifetime ending users that we found. Only valid if check is
95
95
// / successful.
@@ -113,7 +113,7 @@ class SILValueOwnershipChecker {
113
113
public:
114
114
SILValueOwnershipChecker (
115
115
DeadEndBlocks &deadEndBlocks, SILValue value,
116
- LinearLifetimeChecker::ErrorBuilder errorBuilder,
116
+ LinearLifetimeChecker::ErrorBuilder & errorBuilder,
117
117
llvm::SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks)
118
118
: result(), deadEndBlocks(deadEndBlocks), value(value),
119
119
errorBuilder (errorBuilder), visitedBlocks(visitedBlocks) {
@@ -882,8 +882,10 @@ void SILInstruction::verifyOperandOwnership() const {
882
882
}
883
883
}
884
884
885
- static void verifySILValueHelper (const SILFunction *f, SILValue value,
886
- DeadEndBlocks *deadEndBlocks) {
885
+ static void
886
+ verifySILValueHelper (const SILFunction *f, SILValue value,
887
+ LinearLifetimeChecker::ErrorBuilder &errorBuilder,
888
+ DeadEndBlocks *deadEndBlocks) {
887
889
assert (!isa<SILUndef>(value) &&
888
890
" We assume we are always passed arguments or instruction results" );
889
891
@@ -892,21 +894,13 @@ static void verifySILValueHelper(const SILFunction *f, SILValue value,
892
894
if (!f->hasOwnership () || !f->shouldVerifyOwnership ())
893
895
return ;
894
896
895
- using BehaviorKind = LinearLifetimeChecker::ErrorBehaviorKind;
896
- Optional<LinearLifetimeChecker::ErrorBuilder> errorBuilder;
897
- if (IsSILOwnershipVerifierTestingEnabled) {
898
- errorBuilder.emplace (*f, BehaviorKind::PrintMessageAndReturnFalse);
899
- } else {
900
- errorBuilder.emplace (*f, BehaviorKind::PrintMessageAndAssert);
901
- }
902
-
903
897
SmallPtrSet<SILBasicBlock *, 32 > liveBlocks;
904
898
if (deadEndBlocks) {
905
- SILValueOwnershipChecker (*deadEndBlocks, value, * errorBuilder, liveBlocks)
899
+ SILValueOwnershipChecker (*deadEndBlocks, value, errorBuilder, liveBlocks)
906
900
.check ();
907
901
} else {
908
902
DeadEndBlocks deadEndBlocks (f);
909
- SILValueOwnershipChecker (deadEndBlocks, value, * errorBuilder, liveBlocks)
903
+ SILValueOwnershipChecker (deadEndBlocks, value, errorBuilder, liveBlocks)
910
904
.check ();
911
905
}
912
906
}
@@ -951,7 +945,11 @@ void SILValue::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
951
945
// a real function. Assert in case this assumption is no longer true.
952
946
auto *f = (*this )->getFunction ();
953
947
assert (f && " Instructions and arguments should have a function" );
954
- verifySILValueHelper (f, *this , deadEndBlocks);
948
+
949
+ using BehaviorKind = LinearLifetimeChecker::ErrorBehaviorKind;
950
+ LinearLifetimeChecker::ErrorBuilder errorBuilder (
951
+ *f, BehaviorKind::PrintMessageAndAssert);
952
+ verifySILValueHelper (f, *this , errorBuilder, deadEndBlocks);
955
953
}
956
954
957
955
void SILFunction::verifyOwnership (DeadEndBlocks *deadEndBlocks) const {
@@ -976,14 +974,26 @@ void SILFunction::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
976
974
if (!hasOwnership () || !shouldVerifyOwnership ())
977
975
return ;
978
976
977
+ using BehaviorKind = LinearLifetimeChecker::ErrorBehaviorKind;
978
+ unsigned errorCounter = 0 ;
979
+ Optional<LinearLifetimeChecker::ErrorBuilder> errorBuilder;
980
+ if (IsSILOwnershipVerifierTestingEnabled) {
981
+ errorBuilder.emplace (*this , BehaviorKind::PrintMessageAndReturnFalse,
982
+ &errorCounter);
983
+ } else {
984
+ errorBuilder.emplace (*this , BehaviorKind::PrintMessageAndAssert);
985
+ }
986
+
979
987
for (auto &block : *this ) {
980
988
for (auto *arg : block.getArguments ()) {
981
- verifySILValueHelper (this , arg, deadEndBlocks);
989
+ LinearLifetimeChecker::ErrorBuilder newBuilder = *errorBuilder;
990
+ verifySILValueHelper (this , arg, newBuilder, deadEndBlocks);
982
991
}
983
992
984
993
for (auto &inst : block) {
985
994
for (auto result : inst.getResults ()) {
986
- verifySILValueHelper (this , result, deadEndBlocks);
995
+ LinearLifetimeChecker::ErrorBuilder newBuilder = *errorBuilder;
996
+ verifySILValueHelper (this , result, newBuilder, deadEndBlocks);
987
997
}
988
998
}
989
999
}
0 commit comments