Skip to content

TSan: Enable treating inout accesses as Thread Sanitizer writes by de… #8288

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
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: 1 addition & 1 deletion include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace swift {

/// \brief Staging flag for treating inout parameters as Thread Sanitizer
/// accesses.
bool EnableTSANInoutInstrumentation = false;
bool DisableTsanInoutInstrumentation = false;

/// \brief Staging flag for class resilience, which we do not want to enable
/// fully until more code is in place, to allow the standard library to be
Expand Down
6 changes: 3 additions & 3 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ def disable_availability_checking : Flag<["-"],
"disable-availability-checking">,
HelpText<"Disable checking for potentially unavailable APIs">;

def enable_experimental_tsan_inout_instrumentation : Flag<["-"],
"enable-experimental-tsan-inout-instrumentation">,
HelpText<"Enable treatment of inout parameters as Thread Sanitizer accesses">;
def disable_tsan_inout_instrumentation : Flag<["-"],
"disable-tsan-inout-instrumentation">,
HelpText<"Disable treatment of inout parameters as Thread Sanitizer accesses">;

def enable_infer_import_as_member :
Flag<["-"], "enable-infer-import-as-member">,
Expand Down
4 changes: 2 additions & 2 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.DisableAvailabilityChecking |=
Args.hasArg(OPT_disable_availability_checking);

Opts.EnableTSANInoutInstrumentation |=
Args.hasArg(OPT_enable_experimental_tsan_inout_instrumentation);
Opts.DisableTsanInoutInstrumentation |=
Args.hasArg(OPT_disable_tsan_inout_instrumentation);

if (FrontendOpts.InputKind == InputFileKind::IFK_SIL)
Opts.DisableAvailabilityChecking = true;
Expand Down
3 changes: 2 additions & 1 deletion lib/SILGen/SILGenLValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,8 @@ static ManagedValue drillIntoComponent(SILGenFunction &SGF,
addr = std::move(lcomponent).getMaterialized(SGF, loc, base, accessKind);
}

if (SGF.getASTContext().LangOpts.EnableTSANInoutInstrumentation &&
if (!SGF.getASTContext().LangOpts.DisableTsanInoutInstrumentation &&
SGF.getModule().getOptions().Sanitize == SanitizerKind::Thread &&
tsanKind == TSanKind::InoutAccess && !component.isRValue()) {
emitTsanInoutAccess(SGF, loc, addr);
}
Expand Down
2 changes: 1 addition & 1 deletion test/SILGen/tsan_instrumentation.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -sanitize=thread -enable-experimental-tsan-inout-instrumentation -emit-silgen %s | %FileCheck %s
// RUN: %target-swift-frontend -sanitize=thread -emit-silgen %s | %FileCheck %s
// REQUIRES: tsan_runtime
// XFAIL: linux

Expand Down
2 changes: 1 addition & 1 deletion test/Sanitizers/tsan-inout.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %target-build-swift %S/Inputs/tsan-uninstrumented.swift -module-name TSanUninstrumented -emit-module -emit-module-path %T/TSanUninstrumented.swiftmodule -parse-as-library
// RUN: %target-build-swift %S/Inputs/tsan-uninstrumented.swift -c -module-name TSanUninstrumented -parse-as-library -o %T/TSanUninstrumented.o
// RUN: %target-swiftc_driver -Xfrontend -enable-experimental-tsan-inout-instrumentation %s %T/TSanUninstrumented.o -I%T -L%T -g -sanitize=thread -o %t_tsan-binary
// RUN: %target-swiftc_driver %s %T/TSanUninstrumented.o -I%T -L%T -g -sanitize=thread -o %t_tsan-binary
// RUN: not env TSAN_OPTIONS=abort_on_error=0 %target-run %t_tsan-binary 2>&1 | %FileCheck %s
// RUN: not env TSAN_OPTIONS=abort_on_error=0:ignore_interceptors_accesses=0 %target-run %t_tsan-binary 2>&1 | %FileCheck %s --check-prefix CHECK-INTERCEPTORS-ACCESSES
// REQUIRES: executable_test
Expand Down