r226778 - [modules] If we add an implicit special member to a class through an update

Richard Smith richard-llvm at metafoo.co.uk
Wed Jan 21 19:50:31 PST 2015


Author: rsmith
Date: Wed Jan 21 21:50:31 2015
New Revision: 226778

URL: http://llvm.org/viewvc/llvm-project?rev=226778&view=rev
Log:
[modules] If we add an implicit special member to a class through an update
record, and that class declaration is not the canonical definition of the
class, be sure to add the class to the list of classes that are consulted when
we look up a special member in the canonical definition.

Added:
    cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/
    cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/a.h
    cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/b.h
    cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/c.h
    cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/module.modulemap
    cfe/trunk/test/Modules/merge-implicit-special-members.cpp
Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=226778&r1=226777&r2=226778&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Jan 21 21:50:31 2015
@@ -3523,13 +3523,25 @@ void ASTDeclReader::UpdateDecl(Decl *D,
   while (Idx < Record.size()) {
     switch ((DeclUpdateKind)Record[Idx++]) {
     case UPD_CXX_ADDED_IMPLICIT_MEMBER: {
+      auto *RD = cast<CXXRecordDecl>(D);
       // FIXME: If we also have an update record for instantiating the
       // definition of D, we need that to happen before we get here.
       Decl *MD = Reader.ReadDecl(ModuleFile, Record, Idx);
       assert(MD && "couldn't read decl from update record");
       // FIXME: We should call addHiddenDecl instead, to add the member
       // to its DeclContext.
-      cast<CXXRecordDecl>(D)->addedMember(MD);
+      RD->addedMember(MD);
+
+      // If we've added a new special member to a class definition that is not
+      // the canonical definition, then we need special member lookups in the
+      // canonical definition to also look into our class.
+      auto *DD = RD->DefinitionData.getNotUpdated();
+      if (DD && DD->Definition != RD) {
+        auto &Merged = Reader.MergedLookups[DD->Definition];
+        // FIXME: Avoid the linear-time scan here.
+        if (std::find(Merged.begin(), Merged.end(), RD) == Merged.end())
+          Merged.push_back(RD);
+      }
       break;
     }
 

Added: cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/a.h?rev=226778&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/a.h Wed Jan 21 21:50:31 2015
@@ -0,0 +1 @@
+struct pthread_mutex_t { int lock; };

Added: cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/b.h?rev=226778&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/b.h Wed Jan 21 21:50:31 2015
@@ -0,0 +1 @@
+struct pthread_mutex_t { int lock; };

Added: cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/c.h?rev=226778&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/c.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/c.h Wed Jan 21 21:50:31 2015
@@ -0,0 +1,3 @@
+#include "a.h"
+#include "b.h"
+int k = pthread_mutex_t().lock;

Added: cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/module.modulemap?rev=226778&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/merge-implicit-special-members/module.modulemap Wed Jan 21 21:50:31 2015
@@ -0,0 +1,3 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
+module c { header "c.h" export * }

Added: cfe/trunk/test/Modules/merge-implicit-special-members.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-implicit-special-members.cpp?rev=226778&view=auto
==============================================================================
--- cfe/trunk/test/Modules/merge-implicit-special-members.cpp (added)
+++ cfe/trunk/test/Modules/merge-implicit-special-members.cpp Wed Jan 21 21:50:31 2015
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/merge-implicit-special-members -verify %s
+// expected-no-diagnostics
+#include "c.h"
+int n = pthread_mutex_t().lock;





More information about the cfe-commits mailing list