Skip to content

Commit 3dd78ac

Browse files
authored
Merge pull request #9485 from swiftix/verify-all-in-release-mode
[sil-verifier] Make it possible to use -sil-verify-all even in release builds with disabled assertions
2 parents 961eec2 + 4133e30 commit 3dd78ac

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ static llvm::cl::opt<bool> SkipUnreachableMustBeLastErrors(
5252

5353
// The verifier is basically all assertions, so don't compile it with NDEBUG to
5454
// prevent release builds from triggering spurious unused variable warnings.
55-
#ifndef NDEBUG
5655

5756
//===----------------------------------------------------------------------===//
5857
// SILVerifier
@@ -4182,7 +4181,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
41824181

41834182
#undef require
41844183
#undef requireObjectType
4185-
#endif //NDEBUG
41864184

41874185
//===----------------------------------------------------------------------===//
41884186
// Out of Line Verifier Run Functions
@@ -4191,17 +4189,22 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
41914189
/// verify - Run the SIL verifier to make sure that the SILFunction follows
41924190
/// invariants.
41934191
void SILFunction::verify(bool SingleFunction) const {
4194-
#ifndef NDEBUG
4192+
#ifdef NDEBUG
4193+
if (!getModule().getOptions().VerifyAll)
4194+
return;
4195+
#endif
41954196
// Please put all checks in visitSILFunction in SILVerifier, not here. This
41964197
// ensures that the pretty stack trace in the verifier is included with the
41974198
// back trace when the verifier crashes.
41984199
SILVerifier(*this, SingleFunction).verify();
4199-
#endif
42004200
}
42014201

42024202
/// Verify that a vtable follows invariants.
42034203
void SILVTable::verify(const SILModule &M) const {
4204-
#ifndef NDEBUG
4204+
#ifdef NDEBUG
4205+
if (!M.getOptions().VerifyAll)
4206+
return;
4207+
#endif
42054208
for (auto &entry : getEntries()) {
42064209
// All vtable entries must be decls in a class context.
42074210
assert(entry.Method.hasDecl() && "vtable entry is not a decl");
@@ -4254,12 +4257,14 @@ void SILVTable::verify(const SILModule &M) const {
42544257
"vtable entry for " + baseName + " must be ABI-compatible");
42554258
}
42564259
}
4257-
#endif
42584260
}
42594261

42604262
/// Verify that a witness table follows invariants.
42614263
void SILWitnessTable::verify(const SILModule &M) const {
4262-
#ifndef NDEBUG
4264+
#ifdef NDEBUG
4265+
if (!M.getOptions().VerifyAll)
4266+
return;
4267+
#endif
42634268
if (isDeclaration())
42644269
assert(getEntries().size() == 0 &&
42654270
"A witness table declaration should not have any entries.");
@@ -4292,7 +4297,6 @@ void SILWitnessTable::verify(const SILModule &M) const {
42924297
"protocol.");
42934298
}
42944299
}
4295-
#endif
42964300
}
42974301

42984302
/// Verify that a default witness table follows invariants.
@@ -4323,20 +4327,25 @@ void SILDefaultWitnessTable::verify(const SILModule &M) const {
43234327

43244328
/// Verify that a global variable follows invariants.
43254329
void SILGlobalVariable::verify() const {
4326-
#ifndef NDEBUG
4330+
#ifdef NDEBUG
4331+
if (!getModule().getOptions().VerifyAll)
4332+
return;
4333+
#endif
43274334
assert(getLoweredType().isObject()
43284335
&& "global variable cannot have address type");
43294336

43304337
// Verify the static initializer.
43314338
if (InitializerF)
43324339
assert(SILGlobalVariable::canBeStaticInitializer(InitializerF) &&
43334340
"illegal static initializer");
4334-
#endif
43354341
}
43364342

43374343
/// Verify the module.
43384344
void SILModule::verify() const {
4339-
#ifndef NDEBUG
4345+
#ifdef NDEBUG
4346+
if (!getOptions().VerifyAll)
4347+
return;
4348+
#endif
43404349
// Uniquing set to catch symbol name collisions.
43414350
llvm::StringSet<> symbolNames;
43424351

@@ -4406,7 +4415,6 @@ void SILModule::verify() const {
44064415
}
44074416
wt.verify(*this);
44084417
}
4409-
#endif
44104418
}
44114419

44124420
#ifndef NDEBUG

0 commit comments

Comments
 (0)