Skip to content

Commit def6d24

Browse files
committed
Add -verify-exclusivity option (off by default)
1 parent d8e3a87 commit def6d24

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

include/swift/AST/SILOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ class SILOptions {
140140
/// Emit checks to trap at run time when the law of exclusivity is violated.
141141
bool EnforceExclusivityDynamic = true;
142142

143+
/// Emit extra exclusvity markers for memory access and verify coverage.
144+
bool VerifyExclusivity = false;
145+
143146
/// Enable the mandatory semantic arc optimizer.
144147
bool EnableMandatorySemanticARCOpts = false;
145148

include/swift/Option/FrontendOptions.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,10 @@ def fix_string_substring_conversion: Flag<["-"], "fix-string-substring-conversio
457457
def bypass_batch_mode_checks: Flag<["-"], "bypass-batch-mode-checks">,
458458
HelpText<"Bypass checks for batch-mode errors.">;
459459

460+
def enable_verify_exclusivity : Flag<["-"], "enable-verify-exclusivity">,
461+
HelpText<"Enable verification of access markers used to enforce exclusivity.">;
462+
463+
def disable_verify_exclusivity : Flag<["-"], "disable-verify-exclusivity">,
464+
HelpText<"Diable verification of access markers used to enforce exclusivity.">;
465+
460466
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]

lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,12 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
698698
IRGenOpts.Sanitizers = Opts.Sanitizers;
699699
}
700700

701-
if (Opts.shouldOptimize())
701+
if (auto A = Args.getLastArg(OPT_enable_verify_exclusivity,
702+
OPT_disable_verify_exclusivity)) {
703+
Opts.VerifyExclusivity
704+
= A->getOption().matches(OPT_enable_verify_exclusivity);
705+
}
706+
if (Opts.shouldOptimize() && !Opts.VerifyExclusivity)
702707
Opts.EnforceExclusivityDynamic = false;
703708
if (const Arg *A = Args.getLastArg(options::OPT_enforce_exclusivity_EQ)) {
704709
parseExclusivityEnforcementOptions(A, Opts, Diags);

tools/sil-opt/SILOpt.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ static llvm::cl::opt<bool>
8484
EnableSILOpaqueValues("enable-sil-opaque-values",
8585
llvm::cl::desc("Compile the module with sil-opaque-values enabled."));
8686

87+
static llvm::cl::opt<bool>
88+
VerifyExclusivity("enable-verify-exclusivity",
89+
llvm::cl::desc("Verify the access markers used to enforce exclusivity."));
90+
8791
namespace {
8892
enum EnforceExclusivityMode {
8993
Unchecked, // static only
@@ -324,6 +328,7 @@ int main(int argc, char **argv) {
324328
SILOpts.EnableGuaranteedNormalArguments =
325329
EnableGuaranteedNormalArguments;
326330

331+
SILOpts.VerifyExclusivity = VerifyExclusivity;
327332
if (EnforceExclusivity.getNumOccurrences() != 0) {
328333
switch (EnforceExclusivity) {
329334
case EnforceExclusivityMode::Unchecked:

0 commit comments

Comments
 (0)