Skip to content

Commit 44110e3

Browse files
committed
Add a HasAccessMarkers flag to SILFunction.
This allows the verifier to be run before and after marker elimination.
1 parent 41b388d commit 44110e3

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ class SILFunction
208208
/// after the pass runs, we only see a semantic-arc world.
209209
bool HasQualifiedOwnership = true;
210210

211+
/// True if all memory access in this function is demarcated by well-formed
212+
/// memory access markers.
213+
bool HasAccessMarkers = false;
214+
211215
SILFunction(SILModule &module, SILLinkage linkage, StringRef mangledName,
212216
CanSILFunctionType loweredType, GenericEnvironment *genericEnv,
213217
Optional<SILLocation> loc, IsBare_t isBareSILFunction,
@@ -320,6 +324,15 @@ class SILFunction
320324
HasQualifiedOwnership = false;
321325
}
322326

327+
/// Returns true if this function has well-formed access markers describing
328+
/// all memory access.
329+
bool hasAccessMarkers() const { return HasAccessMarkers; }
330+
331+
/// Sets the HasAccessMarkers flag to false.
332+
void disableAccessMarkers() {
333+
HasAccessMarkers = false;
334+
}
335+
323336
/// Returns the calling convention used by this entry point.
324337
SILFunctionTypeRepresentation getRepresentation() const {
325338
return getLoweredFunctionType()->getRepresentation();

lib/SIL/SILFunction.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ SILFunction::SILFunction(SILModule &Module, SILLinkage Linkage, StringRef Name,
9292
ClassVisibility(classVisibility), GlobalInitFlag(false),
9393
InlineStrategy(inlineStrategy), Linkage(unsigned(Linkage)),
9494
KeepAsPublic(false), EffectsKindAttr(E) {
95+
96+
// For bootstrapping, enable access markers in raw SIL whenever enforcement is
97+
// enabled.
98+
if (Module.getStage() == SILStage::Raw
99+
&& (Module.getOptions().EnforceExclusivityDynamic
100+
|| Module.getOptions().EnforceExclusivityStatic)) {
101+
HasAccessMarkers = true;
102+
}
95103
if (InsertBefore)
96104
Module.functions.insert(SILModule::iterator(InsertBefore), this);
97105
else

lib/SIL/SILVerifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
12521252
}
12531253

12541254
void checkBeginAccessInst(BeginAccessInst *BAI) {
1255+
require(F.hasAccessMarkers(), "Unexpected begin_access");
1256+
12551257
auto op = BAI->getOperand();
12561258
requireSameType(BAI->getType(), op->getType(),
12571259
"result must be same type as operand");
@@ -1286,6 +1288,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
12861288
}
12871289

12881290
void checkEndAccessInst(EndAccessInst *EAI) {
1291+
require(F.hasAccessMarkers(), "Unexpected end_access");
1292+
12891293
auto BAI = dyn_cast<BeginAccessInst>(EAI->getOperand());
12901294
require(BAI != nullptr,
12911295
"operand of end_access must be a begin_access");

0 commit comments

Comments
 (0)