From e77de75d7e009daaadb03e9b1091c3a9a9c9d311 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 29 Dec 2015 22:25:14 +0000 Subject: [PATCH] [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 --- clang/lib/AST/MicrosoftMangle.cpp | 12 ++++++------ clang/test/CodeGenCXX/mangle-ms.cpp | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index 3e466c826bee..ba8ff2702793 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -2760,12 +2760,12 @@ void MicrosoftMangleContextImpl::mangleCXXDtor(const CXXDestructorDecl *D, mangler.mangle(D); } -void MicrosoftMangleContextImpl::mangleReferenceTemporary(const VarDecl *VD, - unsigned, - raw_ostream &) { - unsigned DiagID = getDiags().getCustomDiagID(DiagnosticsEngine::Error, - "cannot mangle this reference temporary yet"); - getDiags().Report(VD->getLocation(), DiagID); +void MicrosoftMangleContextImpl::mangleReferenceTemporary( + const VarDecl *VD, unsigned ManglingNumber, raw_ostream &Out) { + MicrosoftCXXNameMangler Mangler(*this, Out); + + Mangler.getStream() << "\01?$RT" << ManglingNumber << '@'; + Mangler.mangle(VD, ""); } void MicrosoftMangleContextImpl::mangleThreadSafeStaticGuardVariable( diff --git a/clang/test/CodeGenCXX/mangle-ms.cpp b/clang/test/CodeGenCXX/mangle-ms.cpp index 22eba63b51c0..d95f781f1204 100644 --- a/clang/test/CodeGenCXX/mangle-ms.cpp +++ b/clang/test/CodeGenCXX/mangle-ms.cpp @@ -21,6 +21,10 @@ int _c(void) {return N::anonymous + c;} // CHECK-DAG: @"\01?_c@@YAHXZ" // X64-DAG: @"\01?_c@@YAHXZ" +const int &NeedsReferenceTemporary = 2; +// CHECK-DAG: @"\01?NeedsReferenceTemporary@@3ABHB" = constant i32* @"\01?$RT1@NeedsReferenceTemporary@@3ABHB" +// X64-DAG: @"\01?NeedsReferenceTemporary@@3AEBHEB" = constant i32* @"\01?$RT1@NeedsReferenceTemporary@@3AEBHEB" + class foo { static const short d; // CHECK-DAG: @"\01?d@foo@@0FB"