Skip to content

Commit e77de75

Browse files
committed
[MS ABI] Invent a mangling for reference temporaries
MSVC is non-conforming and doesn't have a mangling for these. Invent our own to unblock folks using clang. This fixes PR25795. llvm-svn: 256589
1 parent 90bee63 commit e77de75

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,12 +2760,12 @@ void MicrosoftMangleContextImpl::mangleCXXDtor(const CXXDestructorDecl *D,
27602760
mangler.mangle(D);
27612761
}
27622762

2763-
void MicrosoftMangleContextImpl::mangleReferenceTemporary(const VarDecl *VD,
2764-
unsigned,
2765-
raw_ostream &) {
2766-
unsigned DiagID = getDiags().getCustomDiagID(DiagnosticsEngine::Error,
2767-
"cannot mangle this reference temporary yet");
2768-
getDiags().Report(VD->getLocation(), DiagID);
2763+
void MicrosoftMangleContextImpl::mangleReferenceTemporary(
2764+
const VarDecl *VD, unsigned ManglingNumber, raw_ostream &Out) {
2765+
MicrosoftCXXNameMangler Mangler(*this, Out);
2766+
2767+
Mangler.getStream() << "\01?$RT" << ManglingNumber << '@';
2768+
Mangler.mangle(VD, "");
27692769
}
27702770

27712771
void MicrosoftMangleContextImpl::mangleThreadSafeStaticGuardVariable(

clang/test/CodeGenCXX/mangle-ms.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ int _c(void) {return N::anonymous + c;}
2121
// CHECK-DAG: @"\01?_c@@YAHXZ"
2222
// X64-DAG: @"\01?_c@@YAHXZ"
2323

24+
const int &NeedsReferenceTemporary = 2;
25+
// CHECK-DAG: @"\01?NeedsReferenceTemporary@@3ABHB" = constant i32* @"\01?$RT1@NeedsReferenceTemporary@@3ABHB"
26+
// X64-DAG: @"\01?NeedsReferenceTemporary@@3AEBHEB" = constant i32* @"\01?$RT1@NeedsReferenceTemporary@@3AEBHEB"
27+
2428
class foo {
2529
static const short d;
2630
// CHECK-DAG: @"\01?d@foo@@0FB"

0 commit comments

Comments
 (0)