Skip to content

Add a new semantics attribute to disable SIL verification on a function #81520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/AST/SemanticAttrs.def
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,7 @@ SEMANTICS_ATTR(USE_FRAME_POINTER, "use_frame_pointer")
SEMANTICS_ATTR(FIXED_STORAGE_CHECK_INDEX, "fixed_storage.check_index")
SEMANTICS_ATTR(FIXED_STORAGE_GET_COUNT, "fixed_storage.get_count")

SEMANTICS_ATTR(NO_SIL_VERIFICATION, "sil.verify_none")

#undef SEMANTICS_ATTR

9 changes: 9 additions & 0 deletions lib/SIL/Verifier/SILOwnershipVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "swift/AST/Decl.h"
#include "swift/AST/GenericEnvironment.h"
#include "swift/AST/Module.h"
#include "swift/AST/SemanticAttrs.h"
#include "swift/AST/Types.h"
#include "swift/Basic/Assertions.h"
#include "swift/Basic/Range.h"
Expand Down Expand Up @@ -866,6 +867,14 @@ void SILInstruction::verifyOperandOwnership(
return;
#endif

if (getModule().getOptions().VerifyNone) {
return;
}

if (getFunction()->hasSemanticsAttr(semantics::NO_SIL_VERIFICATION)) {
return;
}

// If SILOwnership is not enabled, do not perform verification.
if (!getModule().getOptions().VerifySILOwnership)
return;
Expand Down
4 changes: 4 additions & 0 deletions lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7419,6 +7419,10 @@ void SILFunction::verify(CalleeCache *calleeCache,
if (!verificationEnabled(getModule()))
return;

if (hasSemanticsAttr(semantics::NO_SIL_VERIFICATION)) {
return;
}

// Please put all checks in visitSILFunction in SILVerifier, not here. This
// ensures that the pretty stack trace in the verifier is included with the
// back trace when the verifier crashes.
Expand Down
15 changes: 10 additions & 5 deletions lib/SILOptimizer/Utils/OptimizerBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
//===----------------------------------------------------------------------===//

#include "swift/SILOptimizer/OptimizerBridging.h"
#include "../../IRGen/IRGenModule.h"
#include "swift/AST/SemanticAttrs.h"
#include "swift/SIL/DynamicCasts.h"
#include "swift/SIL/OSSALifetimeCompletion.h"
#include "swift/SIL/SILCloner.h"
#include "swift/SILOptimizer/Analysis/Analysis.h"
#include "swift/SILOptimizer/IPO/ClosureSpecializer.h"
#include "swift/SILOptimizer/Utils/CFGOptUtils.h"
#include "swift/SILOptimizer/Utils/ConstantFolding.h"
#include "swift/SILOptimizer/Utils/Devirtualize.h"
Expand All @@ -21,11 +27,6 @@
#include "swift/SILOptimizer/Utils/SILOptFunctionBuilder.h"
#include "swift/SILOptimizer/Utils/SpecializationMangler.h"
#include "swift/SILOptimizer/Utils/StackNesting.h"
#include "swift/SILOptimizer/IPO/ClosureSpecializer.h"
#include "swift/SIL/DynamicCasts.h"
#include "swift/SIL/OSSALifetimeCompletion.h"
#include "swift/SIL/SILCloner.h"
#include "../../IRGen/IRGenModule.h"

using namespace swift;

Expand Down Expand Up @@ -63,6 +64,10 @@ void SILPassManager::runSwiftFunctionVerification(SILFunction *f) {
if (DisableSwiftVerification)
return;

if (f->hasSemanticsAttr(semantics::NO_SIL_VERIFICATION)) {
return;
}

getSwiftPassInvocation()->beginVerifyFunction(f);
verifyFunctionFunction({getSwiftPassInvocation()}, {f});
getSwiftPassInvocation()->endVerifyFunction();
Expand Down
10 changes: 10 additions & 0 deletions test/SIL/verifier_nofail.sil
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ bb0(%0 : $*P):
%9999 = tuple()
return %9999 : $()
}


class Klass {}

sil [ossa] [_semantics "sil.verify_none"] @foo : $@convention(thin) (@guaranteed Klass) -> () {
bb0(%0 : @guaranteed $Klass):
destroy_value %0
%t = tuple()
return %t
}