]> granicus.if.org Git - clang/commitdiff
AST: Mangle fields in anonymous structs/unions
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 23 Oct 2013 20:52:43 +0000 (20:52 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 23 Oct 2013 20:52:43 +0000 (20:52 +0000)
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
lib/AST/ItaniumMangle.cpp
test/CodeGenCXX/mangle.cpp

index e18afb02c9d7db5179321a38b3aacf64c0f193ba..23e53fffb09d6403f4b3f0a24ffd9fe9645cb053 100644 (file)
@@ -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<FieldDecl>(D)) {
-    //   - a data member of an anonymous union.
-    if (cast<RecordDecl>(Field->getDeclContext())->isAnonymousStructOrUnion())
-      return LinkageInfo::internal();
   }
+  //   - a data member of an anonymous union.
+  assert(!isa<IndirectFieldDecl>(D) && "Didn't expect an IndirectFieldDecl!");
+  assert(!isa<FieldDecl>(D) && "Didn't expect a FieldDecl!");
 
   if (D->isInAnonymousNamespace()) {
     const VarDecl *Var = dyn_cast<VarDecl>(D);
@@ -786,6 +785,7 @@ static LinkageInfo getLVForClassMember(const NamedDecl *D,
   if (!(isa<CXXMethodDecl>(D) ||
         isa<VarDecl>(D) ||
         isa<FieldDecl>(D) ||
+        isa<IndirectFieldDecl>(D) ||
         isa<TagDecl>(D)))
     return LinkageInfo::none();
 
index 0d26c9e163ed0f34320d13a21dc3b1f8c35b6c64..59fa7212de7995a5d8ce5f45910741c9cd64fb84 100644 (file)
@@ -439,6 +439,8 @@ void CXXNameMangler::mangle(const NamedDecl *D, StringRef Prefix) {
     mangleFunctionEncoding(FD);
   else if (const VarDecl *VD = dyn_cast<VarDecl>(D))
     mangleName(VD);
+  else if (const IndirectFieldDecl *IFD = dyn_cast<IndirectFieldDecl>(D))
+    mangleName(IFD->getAnonField());
   else
     mangleName(cast<FieldDecl>(D));
 }
index 775cf00917bed2c2d27db9e5ea769604844e5fd2..4e6dbf5397abbf87504ebc2a43a30c0536baebbf 100644 (file)
@@ -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 <int (foo::*)>
+  struct zed {};
+  void g(zed<&foo::bar>*)
+  {}
+}