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

John McCall rjmccall at apple.com
Tue Aug 2 11:46:33 PDT 2011

On Aug 2, 2011, at 8:49 AM, Sundeep wrote:
> 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.

+      unsigned Align = TI.getWCharAlign() / TI.getCharAlign();

This should be dividing by the bit-width of char, not by its alignment.

Also, there are multiple kinds of wide strings — official wide strings (L),
and then UTF-16 (u) and UTF-32 (U) wide strings.  It would be good if
this worked for all of them.  You should also make sure that you never
*decrease* the alignment of a string, as you might if there were a
utf32 string literal followed by a utf16 string literal which expanded
to the same sequence of bytes.

Also, in the future, please give your patch files some sort of sensible
file extension, preferably ".txt".


More information about the cfe-commits mailing list