summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/atomics
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-06-19 07:08:27 +0000
committerEric Fiselier <eric@efcs.ca>2016-06-19 07:08:27 +0000
commit990952b6644e79da08c6925bddedff7c3b3ebe8a (patch)
tree7f0b05b23564e09db909dca5a6472b011de92cd8 /libcxx/test/std/atomics
parentbe13be47bac8b0d35283cf1525e51a7d1d6e6455 (diff)
downloadbcm5719-llvm-990952b6644e79da08c6925bddedff7c3b3ebe8a.tar.gz
bcm5719-llvm-990952b6644e79da08c6925bddedff7c3b3ebe8a.zip
Fix various undefined behavior found by UBSan.
* Fix non-null violation in strstream.cpp Overflow was calling memcpy with a null parameter and a size of 0. * Fix std/atomics/atomics.flag/ tests: a.test_and_set() was reading from an uninitialized atomic, but wasn't using the value. The tests now clear the flag before performing the first test_and_set. This allows UBSAN to test that clear doesn't read an invalid value. * Fix std/experimental/algorithms/alg.random.sample/sample.pass.cpp The tests were dereferencing a past-the-end pointer to an array so that they could do pointer arithmetic with it. Instead of dereference the iterator I changed the tests to use the special 'base()' test iterator method. * Add -fno-sanitize=float-divide-by-zero to suppress division by zero UBSAN diagnostics. The tests that cause float division by zero are explicitly aware that they are doing that. Since this is well defined for IEEE floats suppress the warnings for now. llvm-svn: 273107
Diffstat (limited to 'libcxx/test/std/atomics')
-rw-r--r--libcxx/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp2
-rw-r--r--libcxx/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp20
-rw-r--r--libcxx/test/std/atomics/atomics.flag/clear.pass.cpp26
3 files changed, 32 insertions, 16 deletions
diff --git a/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp b/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp
index 64093d639e4..22bbbd6af53 100644
--- a/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp
@@ -23,12 +23,14 @@ int main()
{
{
std::atomic_flag f;
+ f.clear();
f.test_and_set();
atomic_flag_clear(&f);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
+ f.clear();
f.test_and_set();
atomic_flag_clear(&f);
assert(f.test_and_set() == 0);
diff --git a/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp
index e1a9349c939..1a212c6f352 100644
--- a/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp
@@ -22,38 +22,44 @@
int main()
{
{
- std::atomic_flag f;
- f.test_and_set();
+ std::atomic_flag f; // uninitialized first
+ atomic_flag_clear_explicit(&f, std::memory_order_relaxed);
+ assert(f.test_and_set() == 0);
atomic_flag_clear_explicit(&f, std::memory_order_relaxed);
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
- f.test_and_set();
+ atomic_flag_clear_explicit(&f, std::memory_order_release);
+ assert(f.test_and_set() == 0);
atomic_flag_clear_explicit(&f, std::memory_order_release);
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
- f.test_and_set();
+ atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);
+ assert(f.test_and_set() == 0);
atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
- f.test_and_set();
+ atomic_flag_clear_explicit(&f, std::memory_order_relaxed);
+ assert(f.test_and_set() == 0);
atomic_flag_clear_explicit(&f, std::memory_order_relaxed);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
- f.test_and_set();
+ atomic_flag_clear_explicit(&f, std::memory_order_release);
+ assert(f.test_and_set() == 0);
atomic_flag_clear_explicit(&f, std::memory_order_release);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
- f.test_and_set();
+ atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);
+ assert(f.test_and_set() == 0);
atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);
assert(f.test_and_set() == 0);
}
diff --git a/libcxx/test/std/atomics/atomics.flag/clear.pass.cpp b/libcxx/test/std/atomics/atomics.flag/clear.pass.cpp
index 65051af790d..255af8f176e 100644
--- a/libcxx/test/std/atomics/atomics.flag/clear.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.flag/clear.pass.cpp
@@ -22,50 +22,58 @@
int main()
{
{
- std::atomic_flag f;
- f.test_and_set();
+ std::atomic_flag f; // uninitialized
+ f.clear();
+ assert(f.test_and_set() == 0);
f.clear();
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
- f.test_and_set();
+ f.clear(std::memory_order_relaxed);
+ assert(f.test_and_set() == 0);
f.clear(std::memory_order_relaxed);
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
- f.test_and_set();
+ f.clear(std::memory_order_release);
+ assert(f.test_and_set() == 0);
f.clear(std::memory_order_release);
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
- f.test_and_set();
+ f.clear(std::memory_order_seq_cst);
+ assert(f.test_and_set() == 0);
f.clear(std::memory_order_seq_cst);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
- f.test_and_set();
+ f.clear();
+ assert(f.test_and_set() == 0);
f.clear();
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
- f.test_and_set();
+ f.clear(std::memory_order_relaxed);
+ assert(f.test_and_set() == 0);
f.clear(std::memory_order_relaxed);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
- f.test_and_set();
+ f.clear(std::memory_order_release);
+ assert(f.test_and_set() == 0);
f.clear(std::memory_order_release);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
- f.test_and_set();
+ f.clear(std::memory_order_seq_cst);
+ assert(f.test_and_set() == 0);
f.clear(std::memory_order_seq_cst);
assert(f.test_and_set() == 0);
}
OpenPOWER on IntegriCloud