Skip to content

Commit 822dc02

Browse files
authored
Merge pull request #22223 from rjmccall/disable-tsan-in-coroutines-5.0
[5.0] Disable TSan in coroutine functions
2 parents a038463 + bc541a2 commit 822dc02

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,13 +1228,19 @@ IRGenSILFunction::IRGenSILFunction(IRGenModule &IGM, SILFunction *f)
12281228
}
12291229
if (IGM.IRGen.Opts.Sanitizers & SanitizerKind::Thread) {
12301230
auto declContext = f->getDeclContext();
1231-
if (declContext && isa<DestructorDecl>(declContext))
1231+
if (f->getLoweredFunctionType()->isCoroutine()) {
1232+
// Disable TSan in coroutines; the instrumentation currently interferes
1233+
// with coroutine structural invariants.
1234+
} else if (declContext && isa<DestructorDecl>(declContext)) {
12321235
// Do not report races in deinit and anything called from it
12331236
// because TSan does not observe synchronization between retain
12341237
// count dropping to '0' and the object deinitialization.
1238+
// Also don't report races in coroutines because the instrumentation
1239+
// code breaks coroutine rules.
12351240
CurFn->addFnAttr("sanitize_thread_no_checking_at_run_time");
1236-
else
1241+
} else {
12371242
CurFn->addFnAttr(llvm::Attribute::SanitizeThread);
1243+
}
12381244
}
12391245

12401246
// 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 -assume-parsing-unqualified-ownership-sil -emit-ir -sanitize=thread %s | %FileCheck %s -check-prefix=TSAN
3+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -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)