[test-suite] r331314 - [test-suite] Fix UB in initialization code for stepanov_container.
David L. Jones via llvm-commits
llvm-commits at lists.llvm.org
Tue May 1 15:25:49 PDT 2018
Author: dlj
Date: Tue May 1 15:25:49 2018
New Revision: 331314
URL: http://llvm.org/viewvc/llvm-project?rev=331314&view=rev
Log:
[test-suite] Fix UB in initialization code for stepanov_container.
This benchmark wants to use vector::operator[] to form a pointer-past-the-end.
This is not valid to do via operator[], because doing so requires forming an
(intermediate) reference-past-the-end (dangling references are always UB, simply
by existing). Forming address-past-the-end is valid under pointer arithmetic
(basic.compound p3.2) and iterators (iterator.requirements.general p7), however.
Modified:
test-suite/trunk/SingleSource/Benchmarks/Misc-C++/stepanov_container.cpp
Modified: test-suite/trunk/SingleSource/Benchmarks/Misc-C++/stepanov_container.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/SingleSource/Benchmarks/Misc-C%2B%2B/stepanov_container.cpp?rev=331314&r1=331313&r2=331314&view=diff
==============================================================================
--- test-suite/trunk/SingleSource/Benchmarks/Misc-C++/stepanov_container.cpp (original)
+++ test-suite/trunk/SingleSource/Benchmarks/Misc-C++/stepanov_container.cpp Tue May 1 15:25:49 2018
@@ -231,7 +231,7 @@ void run_tests(int size)
// make a random test set of the chosen size:
vector<element_t> buf(length);
element_t* buffer = &buf[0];
- element_t* buffer_end = &buf[length];
+ element_t* buffer_end = buffer + length;
initialize(buffer, buffer + size); // elements
initialize(buffer + size, buffer_end); // duplicate elements
random_shuffle(buffer, buffer_end);
@@ -256,4 +256,4 @@ int main()
const int sizes [] = { 100000 };
const int n = sizeof(sizes)/sizeof(int);
for (int i = 0; i < n; ++i) run_tests(sizes[i]);
-}
\ No newline at end of file
+}
More information about the llvm-commits
mailing list