<div dir="ltr">Looks like MSVC also supports u8 string literals.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 21, 2014 at 11:57 AM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: majnemer<br>
Date: Fri Nov 21 13:57:25 2014<br>
New Revision: 222564<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=222564&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=222564&view=rev</a><br>
Log:<br>
MS ABI: Mangle char16_t and char32_t string literals<br>
<br>
We previously had support for char and wchar_t string literals. VS 2015<br>
added support for char16_t and char32_t.<br>
<br>
String literals must be mangled in the MS ABI in order for them to be<br>
deduplicated across translation units: their linker has no notion of<br>
mergeable section. Instead, they use the mangled name to make a COMDAT<br>
for the string literal; the COMDAT will merge with other COMDATs in<br>
other object files.<br>
<br>
This allows strings in object files generated by clang to get merged<br>
with strings in object files generated by MSVC.<br>
<br>
Modified:<br>
cfe/trunk/lib/AST/MicrosoftMangle.cpp<br>
cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp<br>
<br>
Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=222564&r1=222563&r2=222564&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=222564&r1=222563&r2=222564&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)<br>
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Nov 21 13:57:25 2014<br>
@@ -338,9 +338,7 @@ bool MicrosoftMangleContextImpl::shouldM<br>
<br>
bool<br>
MicrosoftMangleContextImpl::shouldMangleStringLiteral(const StringLiteral *SL) {<br>
- return SL->isAscii() || SL->isWide();<br>
- // TODO: This needs to be updated when MSVC gains support for Unicode<br>
- // literals.<br>
+ return SL->isAscii() || SL->isWide() || SL->isUTF16() || SL->isUTF32();<br>
}<br>
<br>
void MicrosoftCXXNameMangler::mangle(const NamedDecl *D, StringRef Prefix) {<br>
@@ -2439,14 +2437,10 @@ void MicrosoftMangleContextImpl::mangleS<br>
Mangler.getStream() << "\01??_C@_";<br>
<br>
// <char-type>: The "kind" of string literal is encoded into the mangled name.<br>
- // TODO: This needs to be updated when MSVC gains support for unicode<br>
- // literals.<br>
- if (SL->isAscii())<br>
- Mangler.getStream() << '0';<br>
- else if (SL->isWide())<br>
+ if (SL->isWide())<br>
Mangler.getStream() << '1';<br>
else<br>
- llvm_unreachable("unexpected string literal kind!");<br>
+ Mangler.getStream() << '0';<br>
<br>
// <literal-length>: The next part of the mangled name consists of the length<br>
// of the string.<br>
@@ -2569,7 +2563,10 @@ void MicrosoftMangleContextImpl::mangleS<br>
unsigned NumCharsToMangle = std::min(32U, SL->getLength());<br>
for (unsigned I = 0, E = NumCharsToMangle * SL->getCharByteWidth(); I != E;<br>
++I)<br>
- MangleByte(GetBigEndianByte(I));<br>
+ if (SL->isWide())<br>
+ MangleByte(GetBigEndianByte(I));<br>
+ else<br>
+ MangleByte(GetLittleEndianByte(I));<br>
<br>
// Encode the NUL terminator if there is room.<br>
if (NumCharsToMangle < 32)<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp?rev=222564&r1=222563&r2=222564&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp?rev=222564&r1=222563&r2=222564&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp Fri Nov 21 13:57:25 2014<br>
@@ -719,3 +719,7 @@ const wchar_t *LongWideString = L"012345<br>
// CHECK: @"\01??_C@_1EK@KFPEBLPK@?$AA0?$AA1?$AA2?$AA3?$AA4?$AA5?$AA6?$AA7?$AA8?$AA9?$AA0?$AA1?$AA2?$AA3?$AA4?$AA5?$AA6?$AA7?$AA8?$AA9?$AA0?$AA1?$AA2?$AA3?$AA4?$AA5?$AA6?$AA7?$AA8?$AA9?$AAA?$AAB@"<br>
const wchar_t *UnicodeLiteral = L"\ud7ff";<br>
// CHECK: @"\01??_C@_13IIHIAFKH@?W?$PP?$AA?$AA@"<br>
+const char16_t *U16Literal = u"hi";<br>
+// CHECK: @"\01??_C@_05OMLEGLOC@h?$AAi?$AA?$AA?$AA@"<br>
+const char32_t *U32Literal = U"hi";<br>
+// CHECK: @"\01??_C@_0M@GFNAJIPG@h?$AA?$AA?$AAi?$AA?$AA?$AA?$AA?$AA?$AA?$AA@"<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>