From 885d8bf8d06ddaf79ffe45a96aaa42621db44241 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 23 Oct 2013 20:52:43 +0000 Subject: [PATCH] AST: Mangle fields in anonymous structs/unions The Itanium mangler couldn't cope with mangling an IndirectFieldDecl. Instead, mangle the field the IndirectFieldDecl refers to. Further, give IndirectFieldDecl no linkage just like FieldDecl. N.B. Decl.cpp:getLVForNamespaceScopeDecl tried to calculate linkage for data members of anonymous structs/unions. However, this seems impossible so turn it into an assertion. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193269 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Decl.cpp | 8 ++++---- lib/AST/ItaniumMangle.cpp | 2 ++ test/CodeGenCXX/mangle.cpp | 9 +++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index e18afb02c9..23e53fffb0 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -575,11 +575,10 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D, // Explicitly declared static. if (Function->getCanonicalDecl()->getStorageClass() == SC_Static) return LinkageInfo(InternalLinkage, DefaultVisibility, false); - } else if (const FieldDecl *Field = dyn_cast(D)) { - // - a data member of an anonymous union. - if (cast(Field->getDeclContext())->isAnonymousStructOrUnion()) - return LinkageInfo::internal(); } + // - a data member of an anonymous union. + assert(!isa(D) && "Didn't expect an IndirectFieldDecl!"); + assert(!isa(D) && "Didn't expect a FieldDecl!"); if (D->isInAnonymousNamespace()) { const VarDecl *Var = dyn_cast(D); @@ -786,6 +785,7 @@ static LinkageInfo getLVForClassMember(const NamedDecl *D, if (!(isa(D) || isa(D) || isa(D) || + isa(D) || isa(D))) return LinkageInfo::none(); diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index 0d26c9e163..59fa7212de 100644 --- a/lib/AST/ItaniumMangle.cpp +++ b/lib/AST/ItaniumMangle.cpp @@ -439,6 +439,8 @@ void CXXNameMangler::mangle(const NamedDecl *D, StringRef Prefix) { mangleFunctionEncoding(FD); else if (const VarDecl *VD = dyn_cast(D)) mangleName(VD); + else if (const IndirectFieldDecl *IFD = dyn_cast(D)) + mangleName(IFD->getAnonField()); else mangleName(cast(D)); } diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp index 775cf00917..4e6dbf5397 100644 --- a/test/CodeGenCXX/mangle.cpp +++ b/test/CodeGenCXX/mangle.cpp @@ -933,3 +933,12 @@ namespace test42 { void g() { func(foo<20, X>()); } } + +namespace test43 { + // CHECK-LABEL: define void @_ZN6test431gEPNS_3zedIXadL_ZNS_3fooUt_3barEEEEE + struct foo { union { int bar; }; }; + template + struct zed {}; + void g(zed<&foo::bar>*) + {} +} -- 2.40.0