Skip to content

Commit 112c3c6

Browse files
committed
[TSan/Exclusivity] Make test more robust against optimization
Add a "black hole" uninstrumented function to the test that prevents the compiler from removing an unused read that needs to be instrumented by TSan for the test to pass. This is needed to prevent the optimizer from removing a useless read when static enforcement of exclusivity is turned on.
1 parent 9cdff5f commit 112c3c6

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

test/Sanitizers/Inputs/tsan-uninstrumented.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ public var computedGlobalInUninstrumentedModule2: Int {
6060
get { return 0 }
6161
set { }
6262
}
63+
64+
public func uninstrumentedBlackHole<T>(_ p: T) { }

test/Sanitizers/tsan-inout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ testRace(name: "InoutAccessToStoredGlobalInUninstrumentedModule",
159159
// the read from the global is IRGen'd to a memcpy().
160160
testRace(name: "ReadAndWriteToStoredGlobalInUninstrumentedModule",
161161
thread: { storedGlobalInUninstrumentedModule2 = 7 },
162-
thread: { _ = storedGlobalInUninstrumentedModule2 } )
162+
thread: { uninstrumentedBlackHole(storedGlobalInUninstrumentedModule2) } )
163163
// CHECK-INTERCEPTORS-ACCESSES-LABEL: Running ReadAndWriteToStoredGlobalInUninstrumentedModule
164164
// CHECK-INTERCEPTORS-ACCESSES: ThreadSanitizer: data race
165165
// CHECK-INTERCEPTORS-ACCESSES: Location is global

0 commit comments

Comments
 (0)