Skip to content

Commit f2d68a2

Browse files
Merge pull request #71162 from nate-chandler/partial-consumption/20240125/1/scope-end-diagnostic
[MoveChecker] Distinguished scope end diagnostics.
2 parents e43fac5 + bff7618 commit f2d68a2

10 files changed

+565
-385
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,12 @@ ERROR(sil_movechecking_capture_consumed, none,
806806
ERROR(sil_movechecking_not_reinitialized_before_end_of_function, none,
807807
"missing reinitialization of %select{inout parameter|closure capture}1 '%0' "
808808
"after consume", (StringRef, bool))
809+
ERROR(sil_movechecking_not_reinitialized_before_end_of_coroutine, none,
810+
"field '%0' was consumed but not reinitialized; "
811+
"the field must be reinitialized during the access", (StringRef))
812+
ERROR(sil_movechecking_not_reinitialized_before_end_of_access, none,
813+
"missing reinitialization of %select{inout parameter|closure capture}1 '%0' "
814+
"after consume while accessing memory", (StringRef, bool))
809815
ERROR(sil_movechecking_value_consumed_in_a_loop, none,
810816
"'%0' consumed in a loop", (StringRef))
811817
ERROR(sil_movechecking_use_after_partial_consume, none,

include/swift/SIL/FieldSensitivePrunedLiveness.h

Lines changed: 77 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,17 +1221,24 @@ class FieldSensitiveSSAPrunedLiveRange
12211221
return inst == defInst.first && defInst.second->contains(bit);
12221222
}
12231223

1224-
bool isDef(SILInstruction *inst, SmallBitVector const &bits) const {
1224+
void isDef(SILInstruction *inst, SmallBitVector const &bits,
1225+
SmallBitVector &bitsOut) const {
1226+
assert(bitsOut.none());
12251227
if (inst != defInst.first)
1226-
return false;
1227-
SmallBitVector defBits(bits.size());
1228-
defInst.second->setBits(defBits);
1229-
return (defBits & bits) == bits;
1228+
return;
1229+
defInst.second->setBits(bitsOut);
1230+
bitsOut &= bits;
12301231
}
12311232

1232-
bool isDef(SILInstruction *inst, TypeTreeLeafTypeRange span) const {
1233-
return inst == defInst.first &&
1234-
defInst.second->setIntersection(span).has_value();
1233+
void isDef(SILInstruction *inst, TypeTreeLeafTypeRange span,
1234+
SmallBitVector &bitsOut) const {
1235+
assert(bitsOut.none());
1236+
if (inst != defInst.first)
1237+
return;
1238+
auto intersection = defInst.second->setIntersection(span);
1239+
if (!intersection.has_value())
1240+
return;
1241+
intersection.value().setBits(bitsOut);
12351242
}
12361243

12371244
bool isDefBlock(SILBasicBlock *block, unsigned bit) const {
@@ -1294,20 +1301,16 @@ class FieldSensitiveMultiDefPrunedLiveRange
12941301
bits, [&](auto range) { initializeDef(def, range); });
12951302
}
12961303

1297-
void initializeDef(SILValue def, TypeTreeLeafTypeRange span) {
1304+
void initializeDef(SILNode *node, TypeTreeLeafTypeRange span) {
12981305
assert(Super::isInitialized());
1299-
defs.insert(def, span);
1300-
auto *block = def->getParentBlock();
1306+
defs.insert(node, span);
1307+
auto *block = node->getParentBlock();
13011308
defBlocks.insert(block, span);
13021309
initializeDefBlock(block, span);
13031310
}
13041311

13051312
void initializeDef(SILInstruction *def, TypeTreeLeafTypeRange span) {
1306-
assert(Super::isInitialized());
1307-
defs.insert(cast<SILNode>(def), span);
1308-
auto *block = def->getParent();
1309-
defBlocks.insert(block, span);
1310-
initializeDefBlock(block, span);
1313+
initializeDef(cast<SILNode>(def), span);
13111314
}
13121315

13131316
bool isInitialized() const { return Super::isInitialized() && !defs.empty(); }
@@ -1322,24 +1325,32 @@ class FieldSensitiveMultiDefPrunedLiveRange
13221325
*iter, [&](TypeTreeLeafTypeRange span) { return span.contains(bit); });
13231326
}
13241327

1325-
bool isDefBlock(SILBasicBlock *block, TypeTreeLeafTypeRange span) const {
1328+
void isDefBlock(SILBasicBlock *block, TypeTreeLeafTypeRange span,
1329+
SmallBitVector &bitsOut) const {
13261330
assert(isInitialized());
1331+
assert(bitsOut.none());
13271332
auto iter = defBlocks.find(block);
13281333
if (!iter)
1329-
return false;
1330-
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
1331-
return span.setIntersection(storedSpan).has_value();
1332-
});
1334+
return;
1335+
for (auto defSpan : *iter) {
1336+
auto intersection = span.setIntersection(defSpan);
1337+
if (!intersection.has_value())
1338+
continue;
1339+
intersection.value().setBits(bitsOut);
1340+
}
13331341
}
13341342

1335-
bool isDefBlock(SILBasicBlock *block, SmallBitVector const &bits) const {
1343+
void isDefBlock(SILBasicBlock *block, SmallBitVector const &bits,
1344+
SmallBitVector &bitsOut) const {
13361345
assert(isInitialized());
1346+
assert(bitsOut.none());
13371347
auto iter = defBlocks.find(block);
13381348
if (!iter)
1339-
return false;
1340-
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
1341-
return storedSpan.intersects(bits);
1342-
});
1349+
return;
1350+
for (auto defSpan : *iter) {
1351+
defSpan.setBits(bitsOut);
1352+
}
1353+
bitsOut &= bits;
13431354
}
13441355

13451356
/// Return true if \p user occurs before the first def in the same basic
@@ -1362,66 +1373,69 @@ class FieldSensitiveMultiDefPrunedLiveRange
13621373
}
13631374
}
13641375

1365-
bool isDef(SILInstruction *inst, unsigned bit) const {
1376+
bool isDef(SILNode *node, unsigned bit) const {
13661377
assert(isInitialized());
1367-
auto iter = defs.find(cast<SILNode>(inst));
1378+
auto iter = defs.find(node);
13681379
if (!iter)
13691380
return false;
13701381
return llvm::any_of(
13711382
*iter, [&](TypeTreeLeafTypeRange span) { return span.contains(bit); });
13721383
}
13731384

1385+
bool isDef(SILInstruction *inst, unsigned bit) const {
1386+
return isDef(cast<SILNode>(inst), bit);
1387+
}
1388+
13741389
bool isDef(SILValue value, unsigned bit) const {
1375-
assert(isInitialized());
1376-
auto iter = defs.find(cast<SILNode>(value));
1377-
if (!iter)
1378-
return false;
1379-
return llvm::any_of(
1380-
*iter, [&](TypeTreeLeafTypeRange span) { return span.contains(bit); });
1390+
return isDef(cast<SILNode>(value), bit);
13811391
}
13821392

1383-
bool isDef(SILValue value, SmallBitVector const &bits) const {
1393+
void isDef(SILNode *node, SmallBitVector const &bits,
1394+
SmallBitVector &bitsOut) const {
13841395
assert(isInitialized());
1385-
auto iter = defs.find(cast<SILNode>(value));
1396+
assert(bitsOut.none());
1397+
auto iter = defs.find(node);
13861398
if (!iter)
1387-
return false;
1388-
SmallBitVector allBits(bits.size());
1399+
return;
13891400
for (auto range : *iter) {
1390-
range.setBits(allBits);
1401+
range.setBits(bitsOut);
13911402
}
1392-
return (bits & allBits) == bits;
1403+
bitsOut &= bits;
1404+
}
1405+
1406+
void isDef(SILValue value, SmallBitVector const &bits,
1407+
SmallBitVector &bitsOut) const {
1408+
isDef(cast<SILNode>(value), bits, bitsOut);
1409+
}
1410+
1411+
void isDef(SILInstruction *inst, SmallBitVector const &bits,
1412+
SmallBitVector &bitsOut) const {
1413+
isDef(cast<SILNode>(inst), bits, bitsOut);
13931414
}
13941415

1395-
bool isDef(SILInstruction *inst, SmallBitVector const &bits) const {
1416+
void isDef(SILNode *node, TypeTreeLeafTypeRange span,
1417+
SmallBitVector &bitsOut) const {
13961418
assert(isInitialized());
1397-
auto iter = defs.find(cast<SILNode>(inst));
1419+
assert(bitsOut.none());
1420+
auto iter = defs.find(node);
13981421
if (!iter)
1399-
return false;
1400-
SmallBitVector allBits(bits.size());
1401-
for (auto range : *iter) {
1402-
range.setBits(allBits);
1422+
return;
1423+
for (auto defSpan : *iter) {
1424+
auto intersection = span.setIntersection(defSpan);
1425+
if (!intersection.has_value())
1426+
continue;
1427+
span.setBits(bitsOut);
14031428
}
1404-
return (bits & allBits) == bits;
14051429
}
14061430

1407-
bool isDef(SILInstruction *inst, TypeTreeLeafTypeRange span) const {
1408-
assert(isInitialized());
1409-
auto iter = defs.find(cast<SILNode>(inst));
1410-
if (!iter)
1411-
return false;
1412-
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
1413-
return span.setIntersection(storedSpan).has_value();
1414-
});
1431+
void isDef(SILInstruction *inst, TypeTreeLeafTypeRange span,
1432+
SmallBitVector &bitsOut) const {
1433+
return isDef(cast<SILNode>(inst), span, bitsOut);
14151434
}
14161435

1417-
bool isDef(SILValue value, TypeTreeLeafTypeRange span) const {
1418-
assert(isInitialized());
1419-
auto iter = defs.find(cast<SILNode>(value));
1420-
if (!iter)
1421-
return false;
1422-
return llvm::any_of(*iter, [&](TypeTreeLeafTypeRange storedSpan) {
1423-
return span.setIntersection(storedSpan).has_value();
1424-
});
1436+
void isDef(SILValue value, TypeTreeLeafTypeRange span,
1437+
SmallBitVector &bitsOut) const {
1438+
return isDef(cast<SILNode>(value), span, bitsOut);
14251439
}
14261440

14271441
void

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4649,9 +4649,9 @@ enum class SILAccessEnforcement : uint8_t {
46494649
/// behavior.
46504650
Unsafe,
46514651

4652-
/// Access to pointers that are signed via pointer authentication mechanishm.
4652+
/// Access to pointers that are signed via pointer authentication.
46534653
/// Such pointers should be authenticated before read and signed before a
4654-
/// write. Optimizer should avoid promoting such accesses to values.
4654+
/// write. Optimizations should avoid promoting such accesses to values.
46554655
Signed,
46564656

46574657
// This enum is encoded.

0 commit comments

Comments
 (0)