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. llvm-svn: 222564
This commit is contained in:
parent
f0a582bada
commit
98e77a2512
|
@ -338,9 +338,7 @@ bool MicrosoftMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) {
|
|||
|
||||
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::mangleStringLiteral(const StringLiteral *SL,
|
|||
Mangler.getStream() << "\01??_C@_";
|
||||
|
||||
// <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::mangleStringLiteral(const StringLiteral *SL,
|
|||
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)
|
||||
|
|
|
@ -719,3 +719,7 @@ const wchar_t *LongWideString = L"012345678901234567890123456789ABCDEF";
|
|||
// 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@"
|
||||
const wchar_t *UnicodeLiteral = L"\ud7ff";
|
||||
// CHECK: @"\01??_C@_13IIHIAFKH@?W?$PP?$AA?$AA@"
|
||||
const char16_t *U16Literal = u"hi";
|
||||
// CHECK: @"\01??_C@_05OMLEGLOC@h?$AAi?$AA?$AA?$AA@"
|
||||
const char32_t *U32Literal = U"hi";
|
||||
// CHECK: @"\01??_C@_0M@GFNAJIPG@h?$AA?$AA?$AAi?$AA?$AA?$AA?$AA?$AA?$AA?$AA@"
|
||||
|
|
Loading…
Reference in New Issue