1212
1313#define DEBUG_TYPE " sil-memory-lifetime-verifier"
1414#include " swift/Basic/Assertions.h"
15- #include " swift/SIL/MemoryLocations.h"
15+ #include " swift/SIL/ApplySite.h"
16+ #include " swift/SIL/BasicBlockDatastructures.h"
17+ #include " swift/SIL/BasicBlockUtils.h"
1618#include " swift/SIL/BitDataflow.h"
1719#include " swift/SIL/CalleeCache.h"
20+ #include " swift/SIL/MemoryLocations.h"
1821#include " swift/SIL/SILBasicBlock.h"
1922#include " swift/SIL/SILFunction.h"
20- #include " swift/SIL/ApplySite.h"
21- #include " swift/SIL/BasicBlockDatastructures.h"
2223#include " llvm/Support/CommandLine.h"
2324
2425using namespace swift ;
@@ -43,6 +44,7 @@ class MemoryLifetimeVerifier {
4344
4445 SILFunction *function;
4546 CalleeCache *calleeCache;
47+ DeadEndBlocks *deadEndBlocks;
4648 MemoryLocations locations;
4749
4850 // / alloc_stack memory locations which are used for store_borrow.
@@ -140,11 +142,12 @@ class MemoryLifetimeVerifier {
140142 }
141143
142144public:
143- MemoryLifetimeVerifier (SILFunction *function, CalleeCache *calleeCache) :
144- function (function),
145- calleeCache (calleeCache),
146- locations (/* handleNonTrivialProjections*/ true ,
147- /* handleTrivialLocations*/ true ) {}
145+ MemoryLifetimeVerifier (SILFunction *function, CalleeCache *calleeCache,
146+ DeadEndBlocks *deadEndBlocks)
147+ : function(function), calleeCache(calleeCache),
148+ deadEndBlocks (deadEndBlocks),
149+ locations(/* handleNonTrivialProjections*/ true ,
150+ /* handleTrivialLocations*/ true ) {}
148151
149152 // / The main entry point to verify the lifetime of all memory locations in
150153 // / the function.
@@ -884,7 +887,12 @@ void MemoryLifetimeVerifier::checkBlock(SILBasicBlock *block, Bits &bits) {
884887 }
885888 case SILInstructionKind::DeallocStackInst: {
886889 SILValue opVal = cast<DeallocStackInst>(&I)->getOperand ();
887- requireBitsClear (bits & nonTrivialLocations, opVal, &I);
890+ if (!deadEndBlocks->isDeadEnd (I.getParent ())) {
891+ // TODO: rdar://159311784: Maybe at some point the invariant will be
892+ // enforced that values stored into addresses
893+ // don't leak in dead-ends.
894+ requireBitsClear (bits & nonTrivialLocations, opVal, &I);
895+ }
888896 // Needed to clear any bits of trivial locations (which are not required
889897 // to be zero).
890898 locations.clearBits (bits, opVal);
@@ -974,7 +982,8 @@ void MemoryLifetimeVerifier::verify() {
974982
975983} // anonymous namespace
976984
977- void SILFunction::verifyMemoryLifetime (CalleeCache *calleeCache) {
978- MemoryLifetimeVerifier verifier (this , calleeCache);
985+ void SILFunction::verifyMemoryLifetime (CalleeCache *calleeCache,
986+ DeadEndBlocks *deadEndBlocks) {
987+ MemoryLifetimeVerifier verifier (this , calleeCache, deadEndBlocks);
979988 verifier.verify ();
980989}
0 commit comments