Skip to content

Commit f7529ea

Browse files
authored
Merge pull request #81520 from meg-gupta/disableverifysemantics
Add a new semantics attribute to disable SIL verification on a function
2 parents 0ed232a + aa01b2a commit f7529ea

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
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
@@ -7430,6 +7430,10 @@ void SILFunction::verify(CalleeCache *calleeCache,
74307430
if (!verificationEnabled(getModule()))
74317431
return;
74327432

7433+
if (hasSemanticsAttr(semantics::NO_SIL_VERIFICATION)) {
7434+
return;
7435+
}
7436+
74337437
// Please put all checks in visitSILFunction in SILVerifier, not here. This
74347438
// ensures that the pretty stack trace in the verifier is included with the
74357439
// back trace when the verifier crashes.

lib/SILOptimizer/Utils/OptimizerBridging.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/SILOptimizer/OptimizerBridging.h"
14+
#include "../../IRGen/IRGenModule.h"
15+
#include "swift/AST/SemanticAttrs.h"
16+
#include "swift/SIL/DynamicCasts.h"
17+
#include "swift/SIL/OSSALifetimeCompletion.h"
18+
#include "swift/SIL/SILCloner.h"
1419
#include "swift/SILOptimizer/Analysis/Analysis.h"
20+
#include "swift/SILOptimizer/IPO/ClosureSpecializer.h"
1521
#include "swift/SILOptimizer/Utils/CFGOptUtils.h"
1622
#include "swift/SILOptimizer/Utils/ConstantFolding.h"
1723
#include "swift/SILOptimizer/Utils/Devirtualize.h"
@@ -21,11 +27,6 @@
2127
#include "swift/SILOptimizer/Utils/SILOptFunctionBuilder.h"
2228
#include "swift/SILOptimizer/Utils/SpecializationMangler.h"
2329
#include "swift/SILOptimizer/Utils/StackNesting.h"
24-
#include "swift/SILOptimizer/IPO/ClosureSpecializer.h"
25-
#include "swift/SIL/DynamicCasts.h"
26-
#include "swift/SIL/OSSALifetimeCompletion.h"
27-
#include "swift/SIL/SILCloner.h"
28-
#include "../../IRGen/IRGenModule.h"
2930

3031
using namespace swift;
3132

@@ -63,6 +64,10 @@ void SILPassManager::runSwiftFunctionVerification(SILFunction *f) {
6364
if (DisableSwiftVerification)
6465
return;
6566

67+
if (f->hasSemanticsAttr(semantics::NO_SIL_VERIFICATION)) {
68+
return;
69+
}
70+
6671
getSwiftPassInvocation()->beginVerifyFunction(f);
6772
verifyFunctionFunction({getSwiftPassInvocation()}, {f});
6873
getSwiftPassInvocation()->endVerifyFunction();

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)