Author: majnemer Date: Thu Oct 22 02:15:56 2015 New Revision: 250997 URL: http://llvm.org/viewvc/llvm-project?rev=250997&view=rev Log: [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. Modified: cfe/trunk/lib/AST/MicrosoftCXXABI.cpp cfe/trunk/lib/AST/MicrosoftMangle.cpp cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp Modified: cfe/trunk/lib/AST/MicrosoftCXXABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftCXXABI.cpp?rev=250997&r1=250996&r2=250997&view=diff ============================================================================== --- cfe/trunk/lib/AST/MicrosoftCXXABI.cpp (original) +++ cfe/trunk/lib/AST/MicrosoftCXXABI.cpp Thu Oct 22 02:15:56 2015 @@ -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, Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=250997&r1=250996&r2=250997&view=diff ============================================================================== --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original) +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Oct 22 02:15:56 2015 @@ -365,7 +365,8 @@ bool MicrosoftMangleContextImpl::shouldM DC = getEffectiveParentContext(DC); if (DC->isTranslationUnit() && D->getFormalLinkage() == InternalLinkage && - !isa<VarTemplateSpecializationDecl>(D)) + !isa<VarTemplateSpecializationDecl>(D) && + D->getIdentifier() != nullptr) return false; } @@ -801,7 +802,7 @@ void MicrosoftCXXNameMangler::mangleUnqu } 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()); Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp?rev=250997&r1=250996&r2=250997&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp (original) +++ cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp Thu Oct 22 02:15:56 2015 @@ -277,3 +277,12 @@ void g() { // CHECK-DAG: @"\01??$f@W4<unnamed-type-E>@?1??g@PR24651@@YAXXZ@@PR24651@@YAXW4<unnamed-type-E>@?1??g@0@YAXXZ@@Z" // CHECK-DAG: @"\01??$f@W4<unnamed-type-E>@?2??g@PR24651@@YAXXZ@@PR24651@@YAXW4<unnamed-type-E>@?2??g@0@YAXXZ@@Z" } + +namespace PR18204 { +template <typename T> +int f(T *); +static union { + int n = f(this); +}; +// CHECK-DAG: @"\01??$f@T<unnamed-type-$S1>@PR18204@@@PR18204@@YAHPAT<unnamed-type-$S1>@0@@Z" +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits