Skip to content

Commit ac08efd

Browse files
committed
[sil] Add a SILVerifier check that all SILUndef's parent function back pointer contains the SILFunction that maps to it.
1 parent 34f87eb commit ac08efd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ class SILFunction
332332
PerformanceConstraints perfConstraints = PerformanceConstraints::None;
333333

334334
/// This is the set of undef values we've created, for uniquing purposes.
335-
llvm::DenseMap<SILType, SILUndef *> undefValues;
335+
///
336+
/// We use a SmallDenseMap since in most functions, we will have only one type
337+
/// of undef if we have any at all. In that case, by staying small we avoid
338+
/// needing a heap allocation.
339+
llvm::SmallDenseMap<SILType, SILUndef *, 1> undefValues;
336340

337341
/// This is the number of uses of this SILFunction inside the SIL.
338342
/// It does not include references from debug scopes.
@@ -1563,6 +1567,12 @@ class SILFunction
15631567
/// This is a fast subset of the checks performed in the SILVerifier.
15641568
void verifyCriticalEdges() const;
15651569

1570+
/// Validate that all SILUndefs stored in the function's type -> SILUndef map
1571+
/// have this function as their parent function.
1572+
///
1573+
/// Please only call this from the SILVerifier.
1574+
void verifySILUndefMap() const;
1575+
15661576
/// Pretty-print the SILFunction.
15671577
void dump(bool Verbose) const;
15681578
void dump() const;

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6902,6 +6902,11 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
69026902
"generic function definition must have a generic environment");
69036903
}
69046904

6905+
// Before verifying the body of the function, validate the SILUndef map to
6906+
// make sure that all SILUndef in the function's map point at the function
6907+
// as the SILUndef's parent.
6908+
F->verifySILUndefMap();
6909+
69056910
// Otherwise, verify the body of the function.
69066911
verifyEntryBlock(F->getEntryBlock());
69076912
verifyEpilogBlocks(F);
@@ -6974,6 +6979,15 @@ void SILFunction::verifyCriticalEdges() const {
69746979
/*checkLinearLifetime=*/ false).verifyBranches(this);
69756980
}
69766981

6982+
/// Validate that all SILUndef in \p f have f as a parent.
6983+
void SILFunction::verifySILUndefMap() const {
6984+
for (auto &pair : undefValues) {
6985+
assert(
6986+
pair.second->getParent() == this &&
6987+
"undef in f->undefValue map with different parent function than f?!");
6988+
}
6989+
}
6990+
69776991
/// Verify that a property descriptor follows invariants.
69786992
void SILProperty::verify(const SILModule &M) const {
69796993
if (!verificationEnabled(M))

0 commit comments

Comments
 (0)