r226761 - [modules] It's possible to merge into the pattern of a class template before we

Richard Smith richard-llvm at metafoo.co.uk
Wed Jan 21 17:41:56 PST 2015


Author: rsmith
Date: Wed Jan 21 19:41:56 2015
New Revision: 226761

URL: http://llvm.org/viewvc/llvm-project?rev=226761&view=rev
Log:
[modules] It's possible to merge into the pattern of a class template before we
load the definition data from the declaration itself. In that case, merge
properly; don't assume the prior definition is the same as our own.

Added:
    cfe/trunk/test/Modules/Inputs/merge-anon-in-template/
    cfe/trunk/test/Modules/Inputs/merge-anon-in-template/a.h
    cfe/trunk/test/Modules/Inputs/merge-anon-in-template/b.h
    cfe/trunk/test/Modules/Inputs/merge-anon-in-template/c.h
    cfe/trunk/test/Modules/Inputs/merge-anon-in-template/module.modulemap
    cfe/trunk/test/Modules/merge-anon-in-template.cc
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=226761&r1=226760&r2=226761&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Jan 21 19:41:56 2015
@@ -1457,9 +1457,13 @@ void ASTDeclReader::ReadCXXRecordDefinit
 
   ReadCXXDefinitionData(*DD, Record, Idx);
 
-  // If we're reading an update record, we might already have a definition for
-  // this record. If so, just merge into it.
-  if (D->DefinitionData.getNotUpdated()) {
+  // We might already have a definition for this record. This can happen either
+  // because we're reading an update record, or because we've already done some
+  // merging. Either way, just merge into it.
+  if (auto *CanonDD = D->DefinitionData.getNotUpdated()) {
+    if (CanonDD->Definition != DD->Definition)
+      Reader.MergedDeclContexts.insert(
+          std::make_pair(DD->Definition, CanonDD->Definition));
     MergeDefinitionData(D, *DD);
     return;
   }

Added: cfe/trunk/test/Modules/Inputs/merge-anon-in-template/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-anon-in-template/a.h?rev=226761&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-anon-in-template/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-anon-in-template/a.h Wed Jan 21 19:41:56 2015
@@ -0,0 +1,4 @@
+template<typename T> struct is_floating {
+  enum { value = 0 };
+  typedef int type;
+};

Added: cfe/trunk/test/Modules/Inputs/merge-anon-in-template/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-anon-in-template/b.h?rev=226761&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-anon-in-template/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-anon-in-template/b.h Wed Jan 21 19:41:56 2015
@@ -0,0 +1,2 @@
+#include "a.h"
+bool k = is_floating<int>::value;

Added: cfe/trunk/test/Modules/Inputs/merge-anon-in-template/c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-anon-in-template/c.h?rev=226761&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-anon-in-template/c.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-anon-in-template/c.h Wed Jan 21 19:41:56 2015
@@ -0,0 +1,6 @@
+template<typename T> struct is_floating {
+  enum { value = 0 };
+  typedef int type;
+};
+#include "b.h"
+bool n20 = is_floating<int>::value;

Added: cfe/trunk/test/Modules/Inputs/merge-anon-in-template/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-anon-in-template/module.modulemap?rev=226761&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/merge-anon-in-template/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/merge-anon-in-template/module.modulemap Wed Jan 21 19:41:56 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-anon-in-template.cc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-anon-in-template.cc?rev=226761&view=auto
==============================================================================
--- cfe/trunk/test/Modules/merge-anon-in-template.cc (added)
+++ cfe/trunk/test/Modules/merge-anon-in-template.cc Wed Jan 21 19:41:56 2015
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/merge-anon-in-template -verify %s
+// expected-no-diagnostics
+#include "a.h"
+#include "c.h"
+is_floating<int>::type t;





More information about the cfe-commits mailing list