[libcxx] r237738 - Fix uninitialized values and bad enum conversions found by UBSAN.

Eric Fiselier eric at efcs.ca
Tue May 19 16:03:57 PDT 2015


Author: ericwf
Date: Tue May 19 18:03:57 2015
New Revision: 237738

URL: http://llvm.org/viewvc/llvm-project?rev=237738&view=rev
Log:
Fix uninitialized values and bad enum conversions found by UBSAN.

Modified:
    libcxx/trunk/test/libcxx/type_traits/convert_to_integral.pass.cpp
    libcxx/trunk/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp
    libcxx/trunk/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp
    libcxx/trunk/test/std/atomics/atomics.flag/clear.pass.cpp

Modified: libcxx/trunk/test/libcxx/type_traits/convert_to_integral.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/type_traits/convert_to_integral.pass.cpp?rev=237738&r1=237737&r2=237738&view=diff
==============================================================================
--- libcxx/trunk/test/libcxx/type_traits/convert_to_integral.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/type_traits/convert_to_integral.pass.cpp Tue May 19 18:03:57 2015
@@ -57,7 +57,7 @@ void check_enum_types()
 }
 
 
-enum enum1 {};
+enum enum1 { zero = 0, one = 1 };
 enum enum2 {
   value = std::numeric_limits<unsigned long>::max()
 };

Modified: libcxx/trunk/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp?rev=237738&r1=237737&r2=237738&view=diff
==============================================================================
--- libcxx/trunk/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp (original)
+++ libcxx/trunk/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp Tue May 19 18:03:57 2015
@@ -22,13 +22,13 @@
 int main()
 {
     {
-        std::atomic_flag f;
+        std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         atomic_flag_clear(&f);
         assert(f.test_and_set() == 0);
     }
     {
-        volatile std::atomic_flag f;
+        volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         atomic_flag_clear(&f);
         assert(f.test_and_set() == 0);

Modified: libcxx/trunk/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp?rev=237738&r1=237737&r2=237738&view=diff
==============================================================================
--- libcxx/trunk/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp (original)
+++ libcxx/trunk/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp Tue May 19 18:03:57 2015
@@ -22,37 +22,37 @@
 int main()
 {
     {
-        std::atomic_flag f;
+        std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         atomic_flag_clear_explicit(&f, std::memory_order_relaxed);
         assert(f.test_and_set() == 0);
     }
     {
-        std::atomic_flag f;
+        std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         atomic_flag_clear_explicit(&f, std::memory_order_release);
         assert(f.test_and_set() == 0);
     }
     {
-        std::atomic_flag f;
+        std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);
         assert(f.test_and_set() == 0);
     }
     {
-        volatile std::atomic_flag f;
+        volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         atomic_flag_clear_explicit(&f, std::memory_order_relaxed);
         assert(f.test_and_set() == 0);
     }
     {
-        volatile std::atomic_flag f;
+        volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         atomic_flag_clear_explicit(&f, std::memory_order_release);
         assert(f.test_and_set() == 0);
     }
     {
-        volatile std::atomic_flag f;
+        volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);
         assert(f.test_and_set() == 0);

Modified: libcxx/trunk/test/std/atomics/atomics.flag/clear.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/atomics/atomics.flag/clear.pass.cpp?rev=237738&r1=237737&r2=237738&view=diff
==============================================================================
--- libcxx/trunk/test/std/atomics/atomics.flag/clear.pass.cpp (original)
+++ libcxx/trunk/test/std/atomics/atomics.flag/clear.pass.cpp Tue May 19 18:03:57 2015
@@ -22,49 +22,49 @@
 int main()
 {
     {
-        std::atomic_flag f;
+        std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         f.clear();
         assert(f.test_and_set() == 0);
     }
     {
-        std::atomic_flag f;
+        std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         f.clear(std::memory_order_relaxed);
         assert(f.test_and_set() == 0);
     }
     {
-        std::atomic_flag f;
+        std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         f.clear(std::memory_order_release);
         assert(f.test_and_set() == 0);
     }
     {
-        std::atomic_flag f;
+        std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         f.clear(std::memory_order_seq_cst);
         assert(f.test_and_set() == 0);
     }
     {
-        volatile std::atomic_flag f;
+        volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         f.clear();
         assert(f.test_and_set() == 0);
     }
     {
-        volatile std::atomic_flag f;
+        volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         f.clear(std::memory_order_relaxed);
         assert(f.test_and_set() == 0);
     }
     {
-        volatile std::atomic_flag f;
+        volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         f.clear(std::memory_order_release);
         assert(f.test_and_set() == 0);
     }
     {
-        volatile std::atomic_flag f;
+        volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
         f.test_and_set();
         f.clear(std::memory_order_seq_cst);
         assert(f.test_and_set() == 0);





More information about the cfe-commits mailing list