@@ -841,17 +841,22 @@ bool GatherUsesVisitor::visitUse(Operand *op, AccessUseType useTy) {
841
841
842
842
// TODO: What about copy_addr of itself. We really should just pre-process
843
843
// those maybe.
844
+ auto leafRange = TypeTreeLeafTypeRange::get (op->get (), getRootAddress ());
845
+ if (!leafRange)
846
+ return false ;
847
+
844
848
assert (!useState.initInsts .count (user));
845
- useState.initInsts .insert (
846
- {user, TypeTreeLeafTypeRange (op->get (), getRootAddress ())});
849
+ useState.initInsts .insert ({user, *leafRange});
847
850
return true ;
848
851
}
849
852
850
853
if (::memInstMustReinitialize (op)) {
851
854
LLVM_DEBUG (llvm::dbgs () << " Found reinit: " << *user);
852
855
assert (!useState.reinitInsts .count (user));
853
- useState.reinitInsts .insert (
854
- {user, TypeTreeLeafTypeRange (op->get (), getRootAddress ())});
856
+ auto leafRange = TypeTreeLeafTypeRange::get (op->get (), getRootAddress ());
857
+ if (!leafRange)
858
+ return false ;
859
+ useState.reinitInsts .insert ({user, *leafRange});
855
860
return true ;
856
861
}
857
862
@@ -891,9 +896,12 @@ bool GatherUsesVisitor::visitUse(Operand *op, AccessUseType useTy) {
891
896
return true ;
892
897
}
893
898
899
+ auto leafRange = TypeTreeLeafTypeRange::get (op->get (), getRootAddress ());
900
+ if (!leafRange)
901
+ return false ;
902
+
894
903
LLVM_DEBUG (llvm::dbgs () << " Found take: " << *user);
895
- useState.takeInsts .insert (
896
- {user, TypeTreeLeafTypeRange (op->get (), getRootAddress ())});
904
+ useState.takeInsts .insert ({user, *leafRange});
897
905
return true ;
898
906
}
899
907
@@ -935,9 +943,13 @@ bool GatherUsesVisitor::visitUse(Operand *op, AccessUseType useTy) {
935
943
936
944
// If set, this will tell the checker that we can change this load into
937
945
// a load_borrow.
946
+ auto leafRange =
947
+ TypeTreeLeafTypeRange::get (op->get (), getRootAddress ());
948
+ if (!leafRange)
949
+ return false ;
950
+
938
951
LLVM_DEBUG (llvm::dbgs () << " Found potential borrow: " << *user);
939
- useState.borrows .insert (
940
- {user, TypeTreeLeafTypeRange (op->get (), getRootAddress ())});
952
+ useState.borrows .insert ({user, *leafRange});
941
953
return true ;
942
954
}
943
955
@@ -963,33 +975,41 @@ bool GatherUsesVisitor::visitUse(Operand *op, AccessUseType useTy) {
963
975
964
976
// Then if we had any final consuming uses, mark that this liveness use is
965
977
// a take and if not, mark this as a borrow.
978
+ auto leafRange = TypeTreeLeafTypeRange::get (op->get (), getRootAddress ());
979
+ if (!leafRange)
980
+ return false ;
981
+
966
982
if (moveChecker.finalConsumingUses .empty ()) {
967
983
LLVM_DEBUG (llvm::dbgs () << " Found borrow inst: " << *user);
968
- useState.borrows .insert (
969
- {user, TypeTreeLeafTypeRange (op->get (), getRootAddress ())});
984
+ useState.borrows .insert ({user, *leafRange});
970
985
} else {
971
986
LLVM_DEBUG (llvm::dbgs () << " Found take inst: " << *user);
972
- useState.takeInsts .insert (
973
- {user, TypeTreeLeafTypeRange (op->get (), getRootAddress ())});
987
+ useState.takeInsts .insert ({user, *leafRange});
974
988
}
975
989
return true ;
976
990
}
977
991
}
978
992
979
993
// Now that we have handled or loadTakeOrCopy, we need to now track our Takes.
980
994
if (::memInstMustConsume (op)) {
995
+ auto leafRange = TypeTreeLeafTypeRange::get (op->get (), getRootAddress ());
996
+ if (!leafRange)
997
+ return false ;
981
998
LLVM_DEBUG (llvm::dbgs () << " Pure consuming use: " << *user);
982
- useState.takeInsts .insert (
983
- {user, TypeTreeLeafTypeRange (op->get (), getRootAddress ())});
999
+ useState.takeInsts .insert ({user, *leafRange});
984
1000
return true ;
985
1001
}
986
1002
987
1003
if (auto fas = FullApplySite::isa (op->getUser ())) {
988
1004
switch (fas.getArgumentConvention (*op)) {
989
- case SILArgumentConvention::Indirect_In_Guaranteed:
990
- useState.livenessUses .insert (
991
- {user, TypeTreeLeafTypeRange (op->get (), getRootAddress ())});
1005
+ case SILArgumentConvention::Indirect_In_Guaranteed: {
1006
+ auto leafRange = TypeTreeLeafTypeRange::get (op->get (), getRootAddress ());
1007
+ if (!leafRange)
1008
+ return false ;
1009
+
1010
+ useState.livenessUses .insert ({user, *leafRange});
992
1011
return true ;
1012
+ }
993
1013
994
1014
case SILArgumentConvention::Indirect_Inout:
995
1015
case SILArgumentConvention::Indirect_InoutAliasable:
@@ -1006,6 +1026,10 @@ bool GatherUsesVisitor::visitUse(Operand *op, AccessUseType useTy) {
1006
1026
// If we don't fit into any of those categories, just track as a liveness
1007
1027
// use. We assume all such uses must only be reads to the memory. So we assert
1008
1028
// to be careful.
1029
+ auto leafRange = TypeTreeLeafTypeRange::get (op->get (), getRootAddress ());
1030
+ if (!leafRange)
1031
+ return false ;
1032
+
1009
1033
LLVM_DEBUG (llvm::dbgs () << " Found liveness use: " << *user);
1010
1034
#ifndef NDEBUG
1011
1035
if (user->mayWriteToMemory ()) {
@@ -1014,8 +1038,7 @@ bool GatherUsesVisitor::visitUse(Operand *op, AccessUseType useTy) {
1014
1038
llvm_unreachable (" standard failure" );
1015
1039
}
1016
1040
#endif
1017
- useState.livenessUses .insert (
1018
- {user, TypeTreeLeafTypeRange (op->get (), getRootAddress ())});
1041
+ useState.livenessUses .insert ({user, *leafRange});
1019
1042
1020
1043
return true ;
1021
1044
}
@@ -1036,8 +1059,26 @@ void MoveOnlyChecker::searchForCandidateMarkMustChecks() {
1036
1059
// Skip any alloc_box due to heap to stack failing on a box capture. This
1037
1060
// will just cause an error.
1038
1061
if (auto *pbi = dyn_cast<ProjectBoxInst>(mmci->getOperand ())) {
1062
+ if (isa<AllocBoxInst>(pbi->getOperand ())) {
1063
+ LLVM_DEBUG (
1064
+ llvm::dbgs ()
1065
+ << " Early emitting diagnostic for unsupported alloc box!\n " );
1066
+ if (mmci->getType ().isMoveOnlyWrapped ()) {
1067
+ diagnose (fn->getASTContext (), mmci->getLoc ().getSourceLoc (),
1068
+ diag::sil_moveonlychecker_not_understand_no_implicit_copy);
1069
+ } else {
1070
+ diagnose (fn->getASTContext (), mmci->getLoc ().getSourceLoc (),
1071
+ diag::sil_moveonlychecker_not_understand_moveonly);
1072
+ }
1073
+ valuesWithDiagnostics.insert (mmci);
1074
+ continue ;
1075
+ }
1076
+
1039
1077
if (auto *bbi = dyn_cast<BeginBorrowInst>(pbi->getOperand ())) {
1040
1078
if (isa<AllocBoxInst>(bbi->getOperand ())) {
1079
+ LLVM_DEBUG (
1080
+ llvm::dbgs ()
1081
+ << " Early emitting diagnostic for unsupported alloc box!\n " );
1041
1082
if (mmci->getType ().isMoveOnlyWrapped ()) {
1042
1083
diagnose (
1043
1084
fn->getASTContext (), mmci->getLoc ().getSourceLoc (),
@@ -1604,6 +1645,8 @@ bool MoveOnlyChecker::check() {
1604
1645
1605
1646
// Perform our address check.
1606
1647
if (!performSingleCheck (markedValue)) {
1648
+ LLVM_DEBUG (llvm::dbgs ()
1649
+ << " Failed to perform single check! Emitting error!\n " );
1607
1650
// If we fail the address check in some way, set the diagnose!
1608
1651
if (markedValue->getType ().isMoveOnlyWrapped ()) {
1609
1652
diagnose (fn->getASTContext (), markedValue->getLoc ().getSourceLoc (),
0 commit comments