Skip to content

Commit 39c525e

Browse files
authored
Merge pull request #23718 from apple/mracek/5.0-tsan-coroutines-fix
[5.0] IRGen: Move coroutine passes to be scheduled before tsan
2 parents 2a5440f + ec736e6 commit 39c525e

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ void swift::performLLVMOptimizations(IRGenOptions &Opts, llvm::Module *Module,
200200
addSwiftContractPass);
201201
}
202202

203+
if (RunSwiftSpecificLLVMOptzns)
204+
addCoroutinePassesToExtensionPoints(PMBuilder);
205+
203206
if (Opts.Sanitizers & SanitizerKind::Address) {
204207
PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
205208
addAddressSanitizerPasses);
@@ -222,10 +225,6 @@ void swift::performLLVMOptimizations(IRGenOptions &Opts, llvm::Module *Module,
222225
PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
223226
addSanitizerCoveragePass);
224227
}
225-
226-
if (RunSwiftSpecificLLVMOptzns)
227-
addCoroutinePassesToExtensionPoints(PMBuilder);
228-
229228
if (RunSwiftSpecificLLVMOptzns)
230229
PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
231230
addSwiftMergeFunctionsPass);

test/IRGen/tsan_coroutines.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// This test case used to crash when tsan ran before co-routine lowering.
2+
// RUN: %target-swift-frontend -emit-ir -sanitize=thread %s | %FileCheck %s
3+
4+
// TSan is currently only supported on 64 bit mac and simulators.
5+
// (We do not test the simulators here.)
6+
// REQUIRES: CPU=x86_64, OS=macosx
7+
8+
public class C { }
9+
10+
public struct Foobar {
11+
var things: [String: C] = [:]
12+
}
13+
14+
extension Foobar {
15+
public struct Index {
16+
fileprivate typealias MyIndex = Dictionary<String, C>.Values.Index
17+
18+
fileprivate let myIndex: MyIndex
19+
20+
fileprivate init(_ index: MyIndex) {
21+
self.myIndex = index
22+
}
23+
}
24+
25+
// We used to crash emitting the subscript function.
26+
// CHECK: define swiftcc { i8*, %T15tsan_coroutines1CC* } @"$s15tsan_coroutines6FoobarVyAA1CCAC5IndexVcir"
27+
@_borrowed
28+
public subscript(position: Index) -> C {
29+
return things.values[position.myIndex]
30+
}
31+
}

0 commit comments

Comments
 (0)