[llvm-commits] PATCH: wide strings alignment fix in clang

Sundeep sundeepk at codeaurora.org
Mon Aug 1 23:34:07 PDT 2011


Hi All,

I have been working on a bug in clang dealing with alignment of wide
strings. Clang is aligning wide string literals to 1 byte boundary. However,
LLVM treats wide strings as 4 byte aligned and generates memory operations
accessing 4 bytes at a time. This works fine on architectures that allow
unaligned access. But for architectures which don't allow unaligned access,
this results in an exception and segfault.

I have attached the patch along with a simple test case to reproduce the
problem.

patch.llvm - clang fix to handle wide string literal alignment correctly.

patch.test - patch to a test case problem in llvm/test regression directory.

wstr_main.c - declares a string "ab" and a wide string L"AZ" and calls foo.
String "ab" causes string literal "AZ" to start from an offset of 3 ('a',
'b', '\0').

wstr_copy.c - attempts to copy a single wide char from L"AZ" into a global
wide string array. This results in unaligned load exception since it tries
to load 4 bytes from an address which is 3 byte aligned.

makefile    - makefile to reproduce the problem.

failures.txt - failure report and explanation from running llvm/test and
projects/test-suite.

This is my first attempt to commit into LLVM repository. I followed
guidelines from "LLVM Developer Policy". Please let me know if I missed
something or if you guys need any additional information.

Thanks,
Sundeep
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.llvm
Type: application/octet-stream
Size: 925 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110802/25432cfd/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.test
Type: application/octet-stream
Size: 858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110802/25432cfd/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: makefile
Type: application/octet-stream
Size: 181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110802/25432cfd/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wstr_copy.c
Type: application/octet-stream
Size: 110 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110802/25432cfd/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wstr_main.c
Type: application/octet-stream
Size: 190 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110802/25432cfd/attachment-0004.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: failures.txt
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110802/25432cfd/attachment.txt>


More information about the llvm-commits mailing list