Skip to content

Commit dcf7014

Browse files
committed
Driver: Parse sanitizer=... as a SIL argument.
This is preparation for a future patch adding experimental support to treat Swift-level inout accesses as Thread Sanitizer writes. That patch will extend the compiler so that additional TSan instrumentation is emitted during SILGen, rather than solely during IRGen and at the LLVM level as occurs now. This patch adds a 'Sanitize' field to SILOptions and moves parsing of 'sanitize=...' to ParseSILArgs() from ParseIRGenArgs() where it is now. The sanitizer-coverage flag remains an IRGen-level option; SILGen does not need to know about the coverage metric.
1 parent 7af65d9 commit dcf7014

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

include/swift/AST/SILOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef SWIFT_AST_SILOPTIONS_H
1919
#define SWIFT_AST_SILOPTIONS_H
2020

21+
#include "swift/Basic/Sanitizers.h"
2122
#include "llvm/ADT/StringRef.h"
2223
#include <string>
2324
#include <climits>
@@ -122,6 +123,12 @@ class SILOptions {
122123

123124
/// Assume that code will be executed in a single-threaded environment.
124125
bool AssumeSingleThreaded = false;
126+
127+
/// Indicates which sanitizer is turned on.
128+
SanitizerKind Sanitize : 2;
129+
130+
SILOptions() : Sanitize(SanitizerKind::None) {}
131+
125132
};
126133

127134
} // end namespace swift

lib/Frontend/CompilerInvocation.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,8 @@ static void PrintArg(raw_ostream &OS, const char *Arg, bool Quote) {
11141114
static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
11151115
IRGenOptions &IRGenOpts,
11161116
FrontendOptions &FEOpts,
1117-
DiagnosticEngine &Diags) {
1117+
DiagnosticEngine &Diags,
1118+
const llvm::Triple &Triple) {
11181119
using namespace options;
11191120

11201121
if (const Arg *A = Args.getLastArg(OPT_sil_inline_threshold)) {
@@ -1228,6 +1229,12 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
12281229
BaseName = FEOpts.ModuleName;
12291230
Opts.SILOutputFileNameForDebugging = BaseName.str();
12301231
}
1232+
1233+
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_EQ)) {
1234+
Opts.Sanitize = parseSanitizerArgValues(A, Triple, Diags);
1235+
IRGenOpts.Sanitize = Opts.Sanitize;
1236+
}
1237+
12311238
return false;
12321239
}
12331240

@@ -1403,10 +1410,6 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
14031410
}
14041411
}
14051412

1406-
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_EQ)) {
1407-
Opts.Sanitize = parseSanitizerArgValues(A, Triple, Diags);
1408-
}
1409-
14101413
if (const Arg *A = Args.getLastArg(options::OPT_sanitize_coverage_EQ)) {
14111414
Opts.SanitizeCoverage =
14121415
parseSanitizerCoverageArgValue(A, Triple, Diags, Opts.Sanitize);
@@ -1474,7 +1477,8 @@ bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
14741477
return true;
14751478
}
14761479

1477-
if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts, Diags)) {
1480+
if (ParseSILArgs(SILOpts, ParsedArgs, IRGenOpts, FrontendOpts, Diags,
1481+
LangOpts.Target)) {
14781482
return true;
14791483
}
14801484

0 commit comments

Comments
 (0)