From 0f43e2c14827e7d77533d9ccb0bd15f8e9c4dd94 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Thu, 22 Oct 2015 07:15:56 +0000 Subject: [PATCH] [MS ABI] Mangle static anonymous unions We believed that internal linkage variables at global scope which are not variable template specializations did not have to be mangled. However, static anonymous unions have no identifier and therefore must be mangled. This fixes PR18204. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250997 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/MicrosoftCXXABI.cpp | 12 +----------- lib/AST/MicrosoftMangle.cpp | 5 +++-- test/CodeGenCXX/mangle-ms-cxx11.cpp | 9 +++++++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/AST/MicrosoftCXXABI.cpp b/lib/AST/MicrosoftCXXABI.cpp index ff84fa5c22..6ba31ccf1e 100644 --- a/lib/AST/MicrosoftCXXABI.cpp +++ b/lib/AST/MicrosoftCXXABI.cpp @@ -89,17 +89,7 @@ public: } bool isNearlyEmpty(const CXXRecordDecl *RD) const override { - // FIXME: Audit the corners - if (!RD->isDynamicClass()) - return false; - - const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); - - // In the Microsoft ABI, classes can have one or two vtable pointers. - CharUnits PointerSize = - Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0)); - return Layout.getNonVirtualSize() == PointerSize || - Layout.getNonVirtualSize() == PointerSize * 2; + llvm_unreachable("unapplicable to the MS ABI"); } void addDefaultArgExprForConstructor(const CXXConstructorDecl *CD, diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index c4baed21cb..5c30ae28b3 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -365,7 +365,8 @@ bool MicrosoftMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) { DC = getEffectiveParentContext(DC); if (DC->isTranslationUnit() && D->getFormalLinkage() == InternalLinkage && - !isa(D)) + !isa(D) && + D->getIdentifier() != nullptr) return false; } @@ -801,7 +802,7 @@ void MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, } else { // Otherwise, number the types using a $S prefix. Name += "$S"; - Name += llvm::utostr(Context.getAnonymousStructId(TD)); + Name += llvm::utostr(Context.getAnonymousStructId(TD) + 1); } Name += ">"; mangleSourceName(Name.str()); diff --git a/test/CodeGenCXX/mangle-ms-cxx11.cpp b/test/CodeGenCXX/mangle-ms-cxx11.cpp index 0a4c602df6..999def87fc 100644 --- a/test/CodeGenCXX/mangle-ms-cxx11.cpp +++ b/test/CodeGenCXX/mangle-ms-cxx11.cpp @@ -277,3 +277,12 @@ void g() { // CHECK-DAG: @"\01??$f@W4@?1??g@PR24651@@YAXXZ@@PR24651@@YAXW4@?1??g@0@YAXXZ@@Z" // CHECK-DAG: @"\01??$f@W4@?2??g@PR24651@@YAXXZ@@PR24651@@YAXW4@?2??g@0@YAXXZ@@Z" } + +namespace PR18204 { +template +int f(T *); +static union { + int n = f(this); +}; +// CHECK-DAG: @"\01??$f@T@PR18204@@@PR18204@@YAHPAT@0@@Z" +} -- 2.40.0