diff --git a/llvm/lib/Support/ConvertUTFWrapper.cpp b/llvm/lib/Support/ConvertUTFWrapper.cpp --- a/llvm/lib/Support/ConvertUTFWrapper.cpp +++ b/llvm/lib/Support/ConvertUTFWrapper.cpp @@ -97,6 +97,8 @@ const UTF16 *Src = reinterpret_cast(SrcBytes.begin()); const UTF16 *SrcEnd = reinterpret_cast(SrcBytes.end()); + assert((uintptr_t)Src % sizeof(UTF16) == 0); + // Byteswap if necessary. std::vector ByteSwapped; if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) { diff --git a/llvm/unittests/Support/ConvertUTFTest.cpp b/llvm/unittests/Support/ConvertUTFTest.cpp --- a/llvm/unittests/Support/ConvertUTFTest.cpp +++ b/llvm/unittests/Support/ConvertUTFTest.cpp @@ -16,7 +16,7 @@ TEST(ConvertUTFTest, ConvertUTF16LittleEndianToUTF8String) { // Src is the look of disapproval. - static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c"; + alignas(UTF16) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c"; ArrayRef Ref(Src, sizeof(Src) - 1); std::string Result; bool Success = convertUTF16ToUTF8String(Ref, Result); @@ -27,7 +27,7 @@ TEST(ConvertUTFTest, ConvertUTF16BigEndianToUTF8String) { // Src is the look of disapproval. - static const char Src[] = "\xfe\xff\x0c\xa0\x00_\x0c\xa0"; + alignas(UTF16) static const char Src[] = "\xfe\xff\x0c\xa0\x00_\x0c\xa0"; ArrayRef Ref(Src, sizeof(Src) - 1); std::string Result; bool Success = convertUTF16ToUTF8String(Ref, Result); @@ -80,7 +80,7 @@ TEST(ConvertUTFTest, UTF16WrappersForConvertUTF16ToUTF8String) { // Src is the look of disapproval. - static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c"; + alignas(UTF16) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c"; ArrayRef SrcRef = makeArrayRef((const UTF16 *)Src, 4); std::string Result; bool Success = convertUTF16ToUTF8String(SrcRef, Result);