[PATCH] D88824: [Support][unittests] Enforce alignment in ConvertUTFTest

Rainer Orth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 04:25:51 PDT 2020


ro created this revision.
ro added reviewers: MaskRay, rupprecht, grimar.
Herald added subscribers: fedor.sergeev, jyknight.
Herald added a project: LLVM.
ro requested review of this revision.

` LLVM-Unit :: Support/./SupportTests/ConvertUTFTest.ConvertUTF16LittleEndianToUTF8String` `FAIL`s on Solaris/sparcv9:

In `llvm/lib/Support/ConvertUTFWrapper.cpp` (`convertUTF16ToUTF8String`) the `SrcBytes` is arg is reinterpreted/accessed as `UTF16` (`unsigned short`, which requires 2-byte alignment on strict-alignment targets like Sparc) without anything guaranteeing the alignment, so the access yields a `SIGBUS`.

This patch avoids this by enforcing the required alignment in the callers.

Tested on `sparcv9-sun-solaris2.11`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88824

Files:
  llvm/unittests/Support/ConvertUTFTest.cpp


Index: llvm/unittests/Support/ConvertUTFTest.cpp
===================================================================
--- llvm/unittests/Support/ConvertUTFTest.cpp
+++ 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";
+  static const char Src[] __attribute__((aligned (sizeof(UTF16)))) = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
   ArrayRef<char> 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";
+  static const char Src[] __attribute__((aligned (sizeof(UTF16)))) = "\xfe\xff\x0c\xa0\x00_\x0c\xa0";
   ArrayRef<char> Ref(Src, sizeof(Src) - 1);
   std::string Result;
   bool Success = convertUTF16ToUTF8String(Ref, Result);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88824.296141.patch
Type: text/x-patch
Size: 1026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201005/23876e37/attachment.bin>


More information about the llvm-commits mailing list