Skip to content

Commit 9523e5c

Browse files
authored
Merge pull request #22222 from rjmccall/disable-tsan-in-coroutines
Disable TSan in coroutine functions
2 parents 0a9b8fa + 0ca3f79 commit 9523e5c

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,13 +1226,17 @@ IRGenSILFunction::IRGenSILFunction(IRGenModule &IGM, SILFunction *f)
12261226
}
12271227
if (IGM.IRGen.Opts.Sanitizers & SanitizerKind::Thread) {
12281228
auto declContext = f->getDeclContext();
1229-
if (declContext && isa<DestructorDecl>(declContext))
1229+
if (f->getLoweredFunctionType()->isCoroutine()) {
1230+
// Disable TSan in coroutines; the instrumentation currently interferes
1231+
// with coroutine structural invariants.
1232+
} else if (declContext && isa<DestructorDecl>(declContext)) {
12301233
// Do not report races in deinit and anything called from it
12311234
// because TSan does not observe synchronization between retain
12321235
// count dropping to '0' and the object deinitialization.
12331236
CurFn->addFnAttr("sanitize_thread_no_checking_at_run_time");
1234-
else
1237+
} else {
12351238
CurFn->addFnAttr(llvm::Attribute::SanitizeThread);
1239+
}
12361240
}
12371241

12381242
// Disable inlining of coroutine functions until we split.

test/IRGen/tsan-attributes.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
// This test verifies that we add the function attributes used by TSan.
22

3-
// RUN: %target-swift-frontend -emit-ir -sanitize=thread %s | %FileCheck %s -check-prefix=TSAN
3+
// RUN: %target-swift-frontend -emit-ir -disable-llvm-optzns -sanitize=thread %s | %FileCheck %s -check-prefix=TSAN
44

55
// TSan is currently only supported on 64 bit mac and simulators.
66
// (We do not test the simulators here.)
77
// REQUIRES: CPU=x86_64, OS=macosx
88

9-
func test() {
9+
// TSAN: define {{.*}} @"$s4main4testyyF"() [[DEFAULT_ATTRS:#[0-9]+]]
10+
public func test() {
1011
}
1112

12-
// TSAN: Function Attrs: sanitize_thread
13+
// TSAN: define {{.*}} @"$s4main1xSivr"({{.*}}) [[COROUTINE_ATTRS:#[0-9]+]]
14+
public var x: Int {
15+
_read {
16+
yield 0
17+
}
18+
}
19+
20+
// TSAN: attributes [[DEFAULT_ATTRS]] =
21+
// TSAN-SAME: sanitize_thread
22+
// TSAN-SAME: }
23+
24+
// TSAN: attributes [[COROUTINE_ATTRS]] =
25+
// TSAN-NOT: sanitize_address
26+
// TSAN-SAME: }

0 commit comments

Comments
 (0)