Skip to content

Commit a279b5d

Browse files
committed
Add a new semantics attribute to disable SIL verification on a function
This provides a way to disable verification per function instead of the entire module.
1 parent 294e4cf commit a279b5d

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

include/swift/AST/SemanticAttrs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,7 @@ SEMANTICS_ATTR(USE_FRAME_POINTER, "use_frame_pointer")
165165
SEMANTICS_ATTR(FIXED_STORAGE_CHECK_INDEX, "fixed_storage.check_index")
166166
SEMANTICS_ATTR(FIXED_STORAGE_GET_COUNT, "fixed_storage.get_count")
167167

168+
SEMANTICS_ATTR(NO_SIL_VERIFICATION, "sil.verify_none")
169+
168170
#undef SEMANTICS_ATTR
169171

lib/SIL/Verifier/SILOwnershipVerifier.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/Decl.h"
2121
#include "swift/AST/GenericEnvironment.h"
2222
#include "swift/AST/Module.h"
23+
#include "swift/AST/SemanticAttrs.h"
2324
#include "swift/AST/Types.h"
2425
#include "swift/Basic/Assertions.h"
2526
#include "swift/Basic/Range.h"
@@ -866,6 +867,14 @@ void SILInstruction::verifyOperandOwnership(
866867
return;
867868
#endif
868869

870+
if (getModule().getOptions().VerifyNone) {
871+
return;
872+
}
873+
874+
if (getFunction()->hasSemanticsAttr(semantics::NO_SIL_VERIFICATION)) {
875+
return;
876+
}
877+
869878
// If SILOwnership is not enabled, do not perform verification.
870879
if (!getModule().getOptions().VerifySILOwnership)
871880
return;

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7419,6 +7419,10 @@ void SILFunction::verify(CalleeCache *calleeCache,
74197419
if (!verificationEnabled(getModule()))
74207420
return;
74217421

7422+
if (hasSemanticsAttr(semantics::NO_SIL_VERIFICATION)) {
7423+
return;
7424+
}
7425+
74227426
// Please put all checks in visitSILFunction in SILVerifier, not here. This
74237427
// ensures that the pretty stack trace in the verifier is included with the
74247428
// back trace when the verifier crashes.

test/SIL/verifier_nofail.sil

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ bb0(%0 : $*P):
2323
%9999 = tuple()
2424
return %9999 : $()
2525
}
26+
27+
28+
class Klass {}
29+
30+
sil [ossa] [_semantics "sil.verify_none"] @foo : $@convention(thin) (@guaranteed Klass) -> () {
31+
bb0(%0 : @guaranteed $Klass):
32+
destroy_value %0
33+
%t = tuple()
34+
return %t
35+
}

0 commit comments

Comments
 (0)