Skip to content

Commit d81c6ba

Browse files
committed
[tsan] Suppress a benign race during metadata cache lookup
This data race is benign and should not occur on the platforms we currently care about. However, do set the ordering appropriately when built with TSan to avoid reporting races from Swift code. The metadata lookup code relies on these orderings for synchronization.
1 parent 5320def commit d81c6ba

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,10 @@ void irgen::emitLazyCacheAccessFunction(IRGenModule &IGM,
10851085
// FIXME: Technically should be "consume", but that introduces barriers in the
10861086
// current LLVM ARM backend.
10871087
auto load = IGF.Builder.CreateLoad(cache);
1088+
// Make this barrier explicit when building for TSan to avoid false positives.
1089+
if (IGM.Opts.Sanitize == SanitizerKind::Thread)
1090+
load->setOrdering(llvm::AtomicOrdering::Acquire);
1091+
10881092

10891093
// Compare the load result against null.
10901094
auto isNullBB = IGF.createBasicBlock("cacheIsNull");

0 commit comments

Comments
 (0)