<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 26, 2015 at 12:52 AM, Yury Gribov <span dir="ltr"><<a href="mailto:tetra2005@gmail.com" target="_blank">tetra2005@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi kcc, samsonov,<br>
<br>
This patch adds constexpr to BlockingMutex which instructs compiler to never generate global constructors (and thus fixes -Wglobal-constructors warnings about BlockingMutex globals in sanitizer_common). I could do the same fixes to other LinkerInitialized classes (Allocator, etc.) and enable -Wglobal-constructors for ASan but I wasn't sure whether anyone needs this.<br>
<br>
REPOSITORY<br>
  rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D7171" target="_blank">http://reviews.llvm.org/D7171</a><br>
<br>
Files:<br>
  lib/sanitizer_common/sanitizer_linux.cc<br>
  lib/sanitizer_common/sanitizer_mac.cc<br>
  lib/sanitizer_common/sanitizer_mutex.h<br>
<br>
Index: lib/sanitizer_common/sanitizer_linux.cc<br>
===================================================================<br>
--- lib/sanitizer_common/sanitizer_linux.cc<br>
+++ lib/sanitizer_common/sanitizer_linux.cc<br>
@@ -493,15 +493,10 @@<br>
   MtxSleeping = 2<br>
 };<br>
<br>
-BlockingMutex::BlockingMutex(LinkerInitialized) {<br>
-  CHECK_EQ(owner_, 0);<br>
-}<br>
-<br>
-BlockingMutex::BlockingMutex() {<br>
-  internal_memset(this, 0, sizeof(*this));<br>
-}<br>
+BlockingMutex::BlockingMutex() {}<br>
<br>
 void BlockingMutex::Lock() {<br>
+  CHECK_EQ(owner_, 0);<br>
   atomic_uint32_t *m = reinterpret_cast<atomic_uint32_t *>(&opaque_storage_);<br>
   if (atomic_exchange(m, MtxLocked, memory_order_acquire) == MtxUnlocked)<br>
     return;<br>
Index: lib/sanitizer_common/sanitizer_mac.cc<br>
===================================================================<br>
--- lib/sanitizer_common/sanitizer_mac.cc<br>
+++ lib/sanitizer_common/sanitizer_mac.cc<br>
@@ -217,13 +217,7 @@<br>
   return sysconf(_SC_PAGESIZE);<br>
 }<br>
<br>
-BlockingMutex::BlockingMutex(LinkerInitialized) {<br>
-  // We assume that OS_SPINLOCK_INIT is zero<br>
-}<br>
-<br>
-BlockingMutex::BlockingMutex() {<br>
-  internal_memset(this, 0, sizeof(*this));<br>
-}<br>
+BlockingMutex::BlockingMutex() {}<br>
<br>
 void BlockingMutex::Lock() {<br>
   CHECK(sizeof(OSSpinLock) <= sizeof(opaque_storage_));<br>
Index: lib/sanitizer_common/sanitizer_mutex.h<br>
===================================================================<br>
--- lib/sanitizer_common/sanitizer_mutex.h<br>
+++ lib/sanitizer_common/sanitizer_mutex.h<br>
@@ -73,14 +73,18 @@<br>
<br>
 class BlockingMutex {<br>
  public:<br>
+#if SANITIZER_WINDOWS<br></blockquote><div><br>Should this be instead based on detecting constexpr support?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   explicit BlockingMutex(LinkerInitialized);<br>
+#else<br>
+  explicit constexpr BlockingMutex(LinkerInitialized) {}<br>
+#endif<br>
   BlockingMutex();<br>
   void Lock();<br>
   void Unlock();<br>
   void CheckLocked();<br>
  private:<br>
-  uptr opaque_storage_[10];<br>
-  uptr owner_;  // for debugging<br>
+  uptr opaque_storage_[10] = {};<br></blockquote><div><br>I imagine these might not compile on the oldest version of MSVC we support (not sure about other compilers in the support matrix)... might be worth checking their respective documentation (linked from the LLVM coding style guide)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  uptr owner_ = 0;  // for debugging<br>
 };<br>
<br>
 // Reader-writer spin mutex.<br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
</blockquote></div><br></div></div>