r223975 - AST: Properly calculate the linkage of a IndirectFieldDecl

David Majnemer david.majnemer at gmail.com
Wed Dec 10 14:58:15 PST 2014


Author: majnemer
Date: Wed Dec 10 16:58:14 2014
New Revision: 223975

URL: http://llvm.org/viewvc/llvm-project?rev=223975&view=rev
Log:
AST: Properly calculate the linkage of a IndirectFieldDecl

getLVForNamespaceScopeDecl believed that it wasn't possible for it to
ever see an IndirectFieldDecl.  However, this can occur when determining
whether or not something is a redeclaration of a member of an anonymous
static union.

This fixes PR21858.

Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/test/SemaCXX/anonymous-union.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=223975&r1=223974&r2=223975&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Wed Dec 10 16:58:14 2014
@@ -619,9 +619,12 @@ static LinkageInfo getLVForNamespaceScop
     // Explicitly declared static.
     if (Function->getCanonicalDecl()->getStorageClass() == SC_Static)
       return LinkageInfo(InternalLinkage, DefaultVisibility, false);
+  } else if (const auto *IFD = dyn_cast<IndirectFieldDecl>(D)) {
+    //   - a data member of an anonymous union.
+    const VarDecl *VD = IFD->getVarDecl();
+    assert(VD && "Expected a VarDecl in this IndirectFieldDecl!");
+    return getLVForNamespaceScopeDecl(VD, computation);
   }
-  //   - 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()) {

Modified: cfe/trunk/test/SemaCXX/anonymous-union.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/anonymous-union.cpp?rev=223975&r1=223974&r2=223975&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/anonymous-union.cpp (original)
+++ cfe/trunk/test/SemaCXX/anonymous-union.cpp Wed Dec 10 16:58:14 2014
@@ -84,6 +84,10 @@ static union {
   float float_val2;
 };
 
+void PR21858() {
+  void int_val2();
+}
+
 void f() {
   int_val2 = 0;
   float_val2 = 0.0;





More information about the cfe-commits mailing list