r222564 - MS ABI: Mangle char16_t and char32_t string literals
Richard Smith
richard at metafoo.co.uk
Fri Nov 21 14:41:18 PST 2014
Looks like MSVC also supports u8 string literals.
On Fri, Nov 21, 2014 at 11:57 AM, David Majnemer <david.majnemer at gmail.com>
wrote:
> Author: majnemer
> Date: Fri Nov 21 13:57:25 2014
> New Revision: 222564
>
> URL: http://llvm.org/viewvc/llvm-project?rev=222564&view=rev
> Log:
> MS ABI: Mangle char16_t and char32_t string literals
>
> We previously had support for char and wchar_t string literals. VS 2015
> added support for char16_t and char32_t.
>
> String literals must be mangled in the MS ABI in order for them to be
> deduplicated across translation units: their linker has no notion of
> mergeable section. Instead, they use the mangled name to make a COMDAT
> for the string literal; the COMDAT will merge with other COMDATs in
> other object files.
>
> This allows strings in object files generated by clang to get merged
> with strings in object files generated by MSVC.
>
> Modified:
> cfe/trunk/lib/AST/MicrosoftMangle.cpp
> cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp
>
> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=222564&r1=222563&r2=222564&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Nov 21 13:57:25 2014
> @@ -338,9 +338,7 @@ bool MicrosoftMangleContextImpl::shouldM
>
> bool
> MicrosoftMangleContextImpl::shouldMangleStringLiteral(const StringLiteral
> *SL) {
> - return SL->isAscii() || SL->isWide();
> - // TODO: This needs to be updated when MSVC gains support for Unicode
> - // literals.
> + return SL->isAscii() || SL->isWide() || SL->isUTF16() || SL->isUTF32();
> }
>
> void MicrosoftCXXNameMangler::mangle(const NamedDecl *D, StringRef
> Prefix) {
> @@ -2439,14 +2437,10 @@ void MicrosoftMangleContextImpl::mangleS
> Mangler.getStream() << "\01??_C at _";
>
> // <char-type>: The "kind" of string literal is encoded into the
> mangled name.
> - // TODO: This needs to be updated when MSVC gains support for unicode
> - // literals.
> - if (SL->isAscii())
> - Mangler.getStream() << '0';
> - else if (SL->isWide())
> + if (SL->isWide())
> Mangler.getStream() << '1';
> else
> - llvm_unreachable("unexpected string literal kind!");
> + Mangler.getStream() << '0';
>
> // <literal-length>: The next part of the mangled name consists of the
> length
> // of the string.
> @@ -2569,7 +2563,10 @@ void MicrosoftMangleContextImpl::mangleS
> unsigned NumCharsToMangle = std::min(32U, SL->getLength());
> for (unsigned I = 0, E = NumCharsToMangle * SL->getCharByteWidth(); I
> != E;
> ++I)
> - MangleByte(GetBigEndianByte(I));
> + if (SL->isWide())
> + MangleByte(GetBigEndianByte(I));
> + else
> + MangleByte(GetLittleEndianByte(I));
>
> // Encode the NUL terminator if there is room.
> if (NumCharsToMangle < 32)
>
> Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp?rev=222564&r1=222563&r2=222564&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/mangle-ms-string-literals.cpp Fri Nov 21
> 13:57:25 2014
> @@ -719,3 +719,7 @@ const wchar_t *LongWideString = L"012345
> // CHECK: @"\01??_C at _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@
> "
> const wchar_t *UnicodeLiteral = L"\ud7ff";
> // CHECK: @"\01??_C at _13IIHIAFKH@?W?$PP?$AA?$AA@"
> +const char16_t *U16Literal = u"hi";
> +// CHECK: @"\01??_C at _05OMLEGLOC@h?$AAi?$AA?$AA?$AA@"
> +const char32_t *U32Literal = U"hi";
> +// CHECK: @"\01??_C at _0M@GFNAJIPG
> @h?$AA?$AA?$AAi?$AA?$AA?$AA?$AA?$AA?$AA?$AA@"
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141121/ba5d0f77/attachment.html>
More information about the cfe-commits
mailing list