r216652 - [modules] When completing the redecl chain for an anonymous declaration in a

Richard Smith richard-llvm at metafoo.co.uk
Wed Aug 27 22:44:07 PDT 2014


Author: rsmith
Date: Thu Aug 28 00:44:07 2014
New Revision: 216652

URL: http://llvm.org/viewvc/llvm-project?rev=216652&view=rev
Log:
[modules] When completing the redecl chain for an anonymous declaration in a
merged context, pull in the lexical decls in that context, since one of them
may complete the redecl chain.

Added:
    cfe/trunk/test/Modules/Inputs/cxx-templates-d.h
Modified:
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/test/Modules/Inputs/cxx-templates-a.h
    cfe/trunk/test/Modules/Inputs/cxx-templates-b.h
    cfe/trunk/test/Modules/Inputs/cxx-templates-common.h
    cfe/trunk/test/Modules/Inputs/module.map
    cfe/trunk/test/Modules/cxx-templates.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=216652&r1=216651&r2=216652&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Aug 28 00:44:07 2014
@@ -6065,9 +6065,7 @@ void ASTReader::CompleteRedeclChain(cons
   // If this is a named declaration, complete it by looking it up
   // within its context.
   //
-  // FIXME: We don't currently handle the cases where we can't do this;
-  // merging a class definition that contains unnamed entities should merge
-  // those entities. Likewise, merging a function definition should merge
+  // FIXME: Merging a function definition should merge
   // all mergeable entities within it.
   if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) ||
       isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) {
@@ -6080,6 +6078,9 @@ void ASTReader::CompleteRedeclChain(cons
           updateOutOfDateIdentifier(*II);
       } else
         DC->lookup(Name);
+    } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) {
+      // FIXME: It'd be nice to do something a bit more targeted here.
+      D->getDeclContext()->decls_begin();
     }
   }
 }
@@ -8310,12 +8311,21 @@ void ASTReader::diagnoseOdrViolations()
       continue;
 
     DeclContext *CanonDef = D->getDeclContext();
-    DeclContext::lookup_result R = CanonDef->lookup(D->getDeclName());
 
     bool Found = false;
     const Decl *DCanon = D->getCanonicalDecl();
 
+    for (auto RI : D->redecls()) {
+      if (RI->getLexicalDeclContext() == CanonDef) {
+        Found = true;
+        break;
+      }
+    }
+    if (Found)
+      continue;
+
     llvm::SmallVector<const NamedDecl*, 4> Candidates;
+    DeclContext::lookup_result R = CanonDef->lookup(D->getDeclName());
     for (DeclContext::lookup_iterator I = R.begin(), E = R.end();
          !Found && I != E; ++I) {
       for (auto RI : (*I)->redecls()) {

Modified: cfe/trunk/test/Modules/Inputs/cxx-templates-a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-templates-a.h?rev=216652&r1=216651&r2=216652&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/cxx-templates-a.h (original)
+++ cfe/trunk/test/Modules/Inputs/cxx-templates-a.h Thu Aug 28 00:44:07 2014
@@ -87,4 +87,5 @@ template<typename T> struct PartiallyIns
 typedef PartiallyInstantiatePartialSpec<int*> PartiallyInstantiatePartialSpecHelper;
 
 void InstantiateWithAliasTemplate(WithAliasTemplate<int>::X<char>);
-inline int InstantiateWithAnonymousDeclsA(WithAnonymousDecls<int> x) { return (x.k ? x.a : x.b) + (x.k ? x.s.c : x.s.d); }
+inline int InstantiateWithAnonymousDeclsA(WithAnonymousDecls<int> x) { return (x.k ? x.a : x.b) + (x.k ? x.s.c : x.s.d) + x.e; }
+inline int InstantiateWithAnonymousDeclsB2(WithAnonymousDecls<char> x);

Modified: cfe/trunk/test/Modules/Inputs/cxx-templates-b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-templates-b.h?rev=216652&r1=216651&r2=216652&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/cxx-templates-b.h (original)
+++ cfe/trunk/test/Modules/Inputs/cxx-templates-b.h Thu Aug 28 00:44:07 2014
@@ -71,7 +71,10 @@ template<typename U> using AliasTemplate
 
 void InstantiateWithAliasTemplate(WithAliasTemplate<int>::X<char>);
 inline int InstantiateWithAnonymousDeclsB(WithAnonymousDecls<int> x) {
-  return (x.k ? x.a : x.b) + (x.k ? x.s.c : x.s.d);
+  return (x.k ? x.a : x.b) + (x.k ? x.s.c : x.s.d) + x.e;
+}
+inline int InstantiateWithAnonymousDeclsB2(WithAnonymousDecls<char> x) {
+  return (x.k ? x.a : x.b) + (x.k ? x.s.c : x.s.d) + x.e;
 }
 
 @import cxx_templates_a;

Modified: cfe/trunk/test/Modules/Inputs/cxx-templates-common.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-templates-common.h?rev=216652&r1=216651&r2=216652&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/cxx-templates-common.h (original)
+++ cfe/trunk/test/Modules/Inputs/cxx-templates-common.h Thu Aug 28 00:44:07 2014
@@ -49,6 +49,7 @@ template<typename T> struct WithAnonymou
   struct { bool k; };
   union { int a, b; };
   struct { int c, d; } s;
+  enum { e = 123 };
   typedef int X;
 };
 

Added: cfe/trunk/test/Modules/Inputs/cxx-templates-d.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-templates-d.h?rev=216652&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/cxx-templates-d.h (added)
+++ cfe/trunk/test/Modules/Inputs/cxx-templates-d.h Thu Aug 28 00:44:07 2014
@@ -0,0 +1,3 @@
+ at import cxx_templates_common;
+
+inline int InstantiateWithAnonymousDeclsD(WithAnonymousDecls<char> x) { return (x.k ? x.a : x.b) + (x.k ? x.s.c : x.s.d) + x.e; }

Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=216652&r1=216651&r2=216652&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Thu Aug 28 00:44:07 2014
@@ -233,6 +233,10 @@ module cxx_templates_c {
   header "cxx-templates-c.h"
 }
 
+module cxx_templates_d {
+  header "cxx-templates-d.h"
+}
+
 module cxx_decls {
   module unimported {
     header "cxx-decls-unimported.h"

Modified: cfe/trunk/test/Modules/cxx-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/cxx-templates.cpp?rev=216652&r1=216651&r2=216652&view=diff
==============================================================================
--- cfe/trunk/test/Modules/cxx-templates.cpp (original)
+++ cfe/trunk/test/Modules/cxx-templates.cpp Thu Aug 28 00:44:07 2014
@@ -12,6 +12,7 @@
 @import cxx_templates_a;
 @import cxx_templates_b;
 @import cxx_templates_c;
+ at import cxx_templates_d;
 @import cxx_templates_common;
 
 template<typename, char> struct Tmpl_T_C {};
@@ -145,9 +146,11 @@ MergeSpecializations<bool>::explicitly_s
 
 using AliasTemplateMergingTest = WithAliasTemplate<int>::X<char>;
 
-int AnonymousDeclsMergingTest(WithAnonymousDecls<int> WAD) {
+int AnonymousDeclsMergingTest(WithAnonymousDecls<int> WAD, WithAnonymousDecls<char> WADC) {
   return InstantiateWithAnonymousDeclsA(WAD) +
-         InstantiateWithAnonymousDeclsB(WAD);
+         InstantiateWithAnonymousDeclsB(WAD) +
+         InstantiateWithAnonymousDeclsB2(WADC) +
+         InstantiateWithAnonymousDeclsD(WADC);
 }
 
 @import cxx_templates_common;





More information about the cfe-commits mailing list