Add a memcpy(a, a, n) test.

clang depends on memcpy where src and dst are the same to actually
work. Even though this is, technically, undefined behavior,
clang is not going to change. Add a test to verify this assumption
holds true for android devices.

Change-Id: Ib575af3c14e705bb62c18fad7d57e1cc0d242899
diff --git a/tests/string_test.cpp b/tests/string_test.cpp
index 96b4143..4b2cca2 100644
--- a/tests/string_test.cpp
+++ b/tests/string_test.cpp
@@ -24,6 +24,9 @@
 #include <math.h>
 #include <stdint.h>
 
+#include <algorithm>
+#include <vector>
+
 #include "buffer_tests.h"
 
 #if defined(NOFORTIFY)
@@ -1432,3 +1435,23 @@
   char dst[6];
   ASSERT_EQ(&dst[4], reinterpret_cast<char*>(mempcpy(dst, "hello", 4)));
 }
+
+// clang depends on the fact that a memcpy where src and dst is the same
+// still operates correctly. This test verifies that this assumption
+// holds true.
+// See https://llvm.org/bugs/show_bug.cgi?id=11763 for more information.
+static std::vector<uint8_t> g_memcpy_same_buffer;
+
+static void DoMemcpySameTest(uint8_t* buffer, size_t len) {
+  memcpy(buffer, g_memcpy_same_buffer.data(), len);
+  ASSERT_EQ(buffer, memcpy(buffer, buffer, len));
+  ASSERT_TRUE(memcmp(buffer, g_memcpy_same_buffer.data(), len) == 0);
+}
+
+TEST(STRING_TEST, memcpy_src_dst_same) {
+  g_memcpy_same_buffer.resize(MEDIUM);
+  for (size_t i = 0; i < MEDIUM; i++) {
+    g_memcpy_same_buffer[i] = i;
+  }
+  RunSingleBufferAlignTest(MEDIUM, DoMemcpySameTest);
+}