<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class="">I trying TSAN on Darwin on LLVM itself (sanitizing multi-threaded ThinLTO link).</div><div class="">However I see two main issues on my debug build: </div><div class=""><br class=""></div><div class="">1) Statistics: the pre/post increment is not safe, it seems to be acknowledge in the code itself:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">    </span><span style="font-variant-ligatures: no-common-ligatures" class="">// FIXME: This function and all those that follow carefully use an</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">    </span><span style="font-variant-ligatures: no-common-ligatures" class="">// atomic operation to update the value safely in the presence of</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">    </span><span style="font-variant-ligatures: no-common-ligatures" class="">// concurrent accesses, but not to read the return value, so the</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">    </span><span style="font-variant-ligatures: no-common-ligatures" class="">// return value is not thread safe.</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Can we tell TSAN to ignore the statistics somehow? Alternatively, is there a fix someone can suggest?</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">2) Pass initialization. This macro does not please TSAN (even though it seems written with TSAN in mind):</div><div class=""><br class=""></div><div class="">#define CALL_ONCE_INITIALIZATION(function) \<br class="">  static volatile sys::cas_flag initialized = 0; \<br class="">  sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \<br class="">  if (old_val == 0) { \<br class="">    function(Registry); \<br class="">    sys::MemoryFence(); \<br class="">    TsanIgnoreWritesBegin(); \<br class="">    TsanHappensBefore(&initialized); \<br class="">    initialized = 2; \<br class="">    TsanIgnoreWritesEnd(); \<br class="">  } else { \<br class="">    sys::cas_flag tmp = initialized; \<br class="">    sys::MemoryFence(); \<br class="">    while (tmp != 2) { \<br class="">      tmp = initialized; \<br class="">      sys::MemoryFence(); \<br class="">    } \<br class="">  } \<br class="">  TsanHappensAfter(&initialized);</div><div class=""><br class=""></div><div class="">The failure looks like:</div><div class=""><br class=""></div><div class="">==================<br class="">WARNING: ThreadSanitizer: data race (pid=17192)<br class="">  Atomic write of size 4 at 0x0001113619e8 by thread T13:<br class="">    #0 __tsan_atomic32_compare_exchange_val <null>:568340296 (libclang_rt.tsan_osx_dynamic.dylib+0x00000003e7aa)<br class="">    #1 llvm::sys::CompareAndSwap(unsigned int volatile*, unsigned int, unsigned int) Atomic.cpp:52 (libLTO.dylib+0x000000511914)<br class="">    #2 llvm::initializeSimpleInlinerPass(llvm::PassRegistry&) InlineSimple.cpp:82 (libLTO.dylib+0x000000ab2b55)<br class="">    #3 (anonymous namespace)::SimpleInliner::SimpleInliner() InlineSimple.cpp:50 (libLTO.dylib+0x000000ab2e8e)<br class="">    #4 (anonymous namespace)::SimpleInliner::SimpleInliner() InlineSimple.cpp:49 (libLTO.dylib+0x000000ab2d19)<br class="">    #5 llvm::createFunctionInliningPass() InlineSimple.cpp:85 (libLTO.dylib+0x000000ab2ce3)</div><div class="">...</div><div class=""><br class="">  Previous read of size 4 at 0x0001113619e8 by thread T14:<br class="">    #0 llvm::initializeSimpleInlinerPass(llvm::PassRegistry&) InlineSimple.cpp:82 (libLTO.dylib+0x000000ab2b65)<br class="">    #1 (anonymous namespace)::SimpleInliner::SimpleInliner() InlineSimple.cpp:50 (libLTO.dylib+0x000000ab2e8e)<br class="">    #2 (anonymous namespace)::SimpleInliner::SimpleInliner() InlineSimple.cpp:49 (libLTO.dylib+0x000000ab2d19)<br class="">    #3 llvm::createFunctionInliningPass() InlineSimple.cpp:85 (libLTO.dylib+0x000000ab2ce3)<br class="">...</div><div class="">  Location is global 'llvm::initializeSimpleInlinerPass(llvm::PassRegistry&)::initialized' at 0x0001113619e8 (libLTO.dylib+0x0000016389e8)<br class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks!</div><div class=""><br class=""></div><div class="">Mehdi</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>