12
12
13
13
#define DEBUG_TYPE " sil-memory-lifetime-verifier"
14
14
#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"
16
18
#include " swift/SIL/BitDataflow.h"
17
19
#include " swift/SIL/CalleeCache.h"
20
+ #include " swift/SIL/MemoryLocations.h"
18
21
#include " swift/SIL/SILBasicBlock.h"
19
22
#include " swift/SIL/SILFunction.h"
20
- #include " swift/SIL/ApplySite.h"
21
- #include " swift/SIL/BasicBlockDatastructures.h"
22
23
#include " llvm/Support/CommandLine.h"
23
24
24
25
using namespace swift ;
@@ -43,6 +44,7 @@ class MemoryLifetimeVerifier {
43
44
44
45
SILFunction *function;
45
46
CalleeCache *calleeCache;
47
+ DeadEndBlocks *deadEndBlocks;
46
48
MemoryLocations locations;
47
49
48
50
// / alloc_stack memory locations which are used for store_borrow.
@@ -140,11 +142,12 @@ class MemoryLifetimeVerifier {
140
142
}
141
143
142
144
public:
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 ) {}
148
151
149
152
// / The main entry point to verify the lifetime of all memory locations in
150
153
// / the function.
@@ -883,7 +886,12 @@ void MemoryLifetimeVerifier::checkBlock(SILBasicBlock *block, Bits &bits) {
883
886
}
884
887
case SILInstructionKind::DeallocStackInst: {
885
888
SILValue opVal = cast<DeallocStackInst>(&I)->getOperand ();
886
- requireBitsClear (bits & nonTrivialLocations, opVal, &I);
889
+ if (!deadEndBlocks->isDeadEnd (I.getParent ())) {
890
+ // TODO: rdar://159311784: Maybe at some point the invariant will be
891
+ // enforced that values stored into addresses
892
+ // don't leak in dead-ends.
893
+ requireBitsClear (bits & nonTrivialLocations, opVal, &I);
894
+ }
887
895
// Needed to clear any bits of trivial locations (which are not required
888
896
// to be zero).
889
897
locations.clearBits (bits, opVal);
@@ -973,7 +981,8 @@ void MemoryLifetimeVerifier::verify() {
973
981
974
982
} // anonymous namespace
975
983
976
- void SILFunction::verifyMemoryLifetime (CalleeCache *calleeCache) {
977
- MemoryLifetimeVerifier verifier (this , calleeCache);
984
+ void SILFunction::verifyMemoryLifetime (CalleeCache *calleeCache,
985
+ DeadEndBlocks *deadEndBlocks) {
986
+ MemoryLifetimeVerifier verifier (this , calleeCache, deadEndBlocks);
978
987
verifier.verify ();
979
988
}
0 commit comments