diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-06-26 19:48:29 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-06-26 19:48:29 +0000 |
commit | 2e0e3df9da62aa55b95b197abb28c385a328c427 (patch) | |
tree | fc96c7c4c0fcbb18a21db614e478315346e4ad17 | |
parent | 3740071be01c10a387f12c01194e6cde2e8299bb (diff) | |
download | bcm5719-llvm-2e0e3df9da62aa55b95b197abb28c385a328c427.tar.gz bcm5719-llvm-2e0e3df9da62aa55b95b197abb28c385a328c427.zip |
Add array bounds assertions to satisfy MSVC's /analyze flag. Patch from STL@microsoft.com
llvm-svn: 273820
3 files changed, 11 insertions, 0 deletions
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp index 7bb43461cba..62458eca930 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort.pass.cpp @@ -22,13 +22,17 @@ void test_larger_sorts(unsigned N, unsigned M) { assert(N != 0); + assert(N >= M); int* array = new int[N]; for (int i = 0; i < N; ++i) array[i] = i; std::random_shuffle(array, array+N); std::partial_sort(array, array+M, array+N); for (int i = 0; i < M; ++i) + { + assert(i < N); // quiet analysis warnings assert(array[i] == i); + } delete [] array; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp index 4b7c5ee64c2..0289cf8391f 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/partial.sort/partial_sort_comp.pass.cpp @@ -35,13 +35,17 @@ void test_larger_sorts(unsigned N, unsigned M) { assert(N != 0); + assert(N >= M); int* array = new int[N]; for (int i = 0; i < N; ++i) array[i] = i; std::random_shuffle(array, array+N); std::partial_sort(array, array+M, array+N, std::greater<int>()); for (int i = 0; i < M; ++i) + { + assert(i < N); // quiet analysis warnings assert(array[i] == N-i-1); + } delete [] array; } diff --git a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp index 8ee029cd6dd..03da9b8960e 100644 --- a/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp +++ b/libcxx/test/std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp @@ -243,6 +243,7 @@ test4() a = 0; for (int j = 0; j < k; ++j) a += areas[j]; + assert(k < Np); m = (p[k+1] - p[k]) / (b[k+1] - b[k]); bk = b[k]; c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); @@ -281,6 +282,7 @@ test5() double S = 0; for (int i = 0; i < areas.size(); ++i) { + assert(i < Np); areas[i] = (p[i]+p[i+1])*(b[i+1]-b[i])/2; S += areas[i]; } @@ -296,6 +298,7 @@ test5() a = 0; for (int j = 0; j < k; ++j) a += areas[j]; + assert(k < Np); m = (p[k+1] - p[k]) / (b[k+1] - b[k]); bk = b[k]; c = (b[k+1]*p[k] - b[k]*p[k+1]) / (b[k+1] - b[k]); |