]> granicus.if.org Git - libatomic_ops/commitdiff
Fix 'unknown attribute no_sanitize' compiler warning (clang prior to v3.8)
authorIvan Maidanski <ivmai@mail.ru>
Mon, 20 Feb 2017 20:30:55 +0000 (23:30 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 20 Feb 2017 20:30:55 +0000 (23:30 +0300)
* src/atomic_ops.h [!AO_ATTR_NO_SANITIZE_MEMORY && AO_MEMORY_SANITIZER]
(AO_ATTR_NO_SANITIZE_MEMORY): Do not define to no_sanitize attribute
unless clang-3.8+ (or not clang).
* tests/test_atomic_include.template [AO_HAVE_storeXX
&& AO_MEMORY_SANITIZER && AO_PREFER_GENERALIZED] (test_atomicXX):
Initialize x local variable (before AO_storeXX which can be defined
using CAS); add comment.
* tests/test_atomic_include.template [AO_HAVE_short_storeXX
&& AO_MEMORY_SANITIZER && AO_PREFER_GENERALIZED] (test_atomicXX):
Initialize s local variable.
* tests/test_atomic_include.template [AO_HAVE_char_storeXX
&& AO_MEMORY_SANITIZER && AO_PREFER_GENERALIZED] (test_atomicXX):
Initialize b local variable.
* tests/test_atomic_include.template [AO_HAVE_int_storeXX
&& AO_MEMORY_SANITIZER && AO_PREFER_GENERALIZED] (test_atomicXX):
Initialize zz local variable.

src/atomic_ops.h
tests/test_atomic_include.template

index 171f10005c2278d9fafe254daf8af4c537c50664..6f5f1923f0fbf0eac5b962a88d18999e9c779be6 100644 (file)
 #endif
 
 #ifndef AO_ATTR_NO_SANITIZE_MEMORY
-# ifdef AO_MEMORY_SANITIZER
+# if defined(AO_MEMORY_SANITIZER) \
+        && (!defined(__clang__) || __clang_major__ > 3 \
+            || (__clang_major__ == 3 && __clang_minor__ >= 8))
 #   define AO_ATTR_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))
 # else
 #   define AO_ATTR_NO_SANITIZE_MEMORY /* empty */
index 12cceedf727d0cec601412cee70d22c99b34afac..b6bcc18248e0b11209e9031a185095823b003eb4 100644 (file)
@@ -61,6 +61,9 @@ void test_atomicXX(void)
     MISSING(AO_nop);
 # endif
 # if defined(AO_HAVE_storeXX)
+#   if defined(AO_MEMORY_SANITIZER) && defined(AO_PREFER_GENERALIZED)
+      *(volatile AO_t *)&x = 0; /* initialize to avoid MSan false warning */
+#   endif
     AO_storeXX(&x, 13);
     TA_assert(x == 13);
 # else
@@ -107,6 +110,9 @@ void test_atomicXX(void)
     --x;
 # endif
 # if defined(AO_HAVE_short_storeXX)
+#   if defined(AO_MEMORY_SANITIZER) && defined(AO_PREFER_GENERALIZED)
+      *(volatile short *)&s = 0;
+#   endif
     AO_short_storeXX(&s, 13);
 # else
 #   if !defined(AO_HAVE_short_store) || !defined(AO_HAVE_short_store_full) \
@@ -146,6 +152,9 @@ void test_atomicXX(void)
 # endif
   TA_assert(*(volatile short *)&s == 13);
 # if defined(AO_HAVE_char_storeXX)
+#   if defined(AO_MEMORY_SANITIZER) && defined(AO_PREFER_GENERALIZED)
+      *(volatile char *)&b = 0;
+#   endif
     AO_char_storeXX(&b, 13);
 # else
 #   if !defined(AO_HAVE_char_store) || !defined(AO_HAVE_char_store_full) \
@@ -184,6 +193,9 @@ void test_atomicXX(void)
 # endif
   TA_assert(*(volatile char *)&b == 13);
 # if defined(AO_HAVE_int_storeXX)
+#   if defined(AO_MEMORY_SANITIZER) && defined(AO_PREFER_GENERALIZED)
+      *(volatile int *)&zz = 0;
+#   endif
     AO_int_storeXX(&zz, 13);
 # else
 #   if !defined(AO_HAVE_int_store) || !defined(AO_HAVE_int_store_full) \