summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-01-22 01:41:56 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-01-22 01:41:56 +0000
commit5156c3857066396e744137cdadf94fb18fa29da2 (patch)
treeafcc4c56db5547c8bd452d99b338bb50e81f8b55 /clang
parent1d59f99f5c1c28035bd5fa35626d5813dc2b0500 (diff)
downloadbcm5719-llvm-5156c3857066396e744137cdadf94fb18fa29da2.tar.gz
bcm5719-llvm-5156c3857066396e744137cdadf94fb18fa29da2.zip
[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. llvm-svn: 226761
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Serialization/ASTReaderDecl.cpp10
-rw-r--r--clang/test/Modules/Inputs/merge-anon-in-template/a.h4
-rw-r--r--clang/test/Modules/Inputs/merge-anon-in-template/b.h2
-rw-r--r--clang/test/Modules/Inputs/merge-anon-in-template/c.h6
-rw-r--r--clang/test/Modules/Inputs/merge-anon-in-template/module.modulemap3
-rw-r--r--clang/test/Modules/merge-anon-in-template.cc6
6 files changed, 28 insertions, 3 deletions
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index a783183d2ef..8c03b0b8b27 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1457,9 +1457,13 @@ void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D) {
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;
}
diff --git a/clang/test/Modules/Inputs/merge-anon-in-template/a.h b/clang/test/Modules/Inputs/merge-anon-in-template/a.h
new file mode 100644
index 00000000000..82540e397bf
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-anon-in-template/a.h
@@ -0,0 +1,4 @@
+template<typename T> struct is_floating {
+ enum { value = 0 };
+ typedef int type;
+};
diff --git a/clang/test/Modules/Inputs/merge-anon-in-template/b.h b/clang/test/Modules/Inputs/merge-anon-in-template/b.h
new file mode 100644
index 00000000000..87c053d962d
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-anon-in-template/b.h
@@ -0,0 +1,2 @@
+#include "a.h"
+bool k = is_floating<int>::value;
diff --git a/clang/test/Modules/Inputs/merge-anon-in-template/c.h b/clang/test/Modules/Inputs/merge-anon-in-template/c.h
new file mode 100644
index 00000000000..e0b9b0a3317
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-anon-in-template/c.h
@@ -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;
diff --git a/clang/test/Modules/Inputs/merge-anon-in-template/module.modulemap b/clang/test/Modules/Inputs/merge-anon-in-template/module.modulemap
new file mode 100644
index 00000000000..77e0a89e39a
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-anon-in-template/module.modulemap
@@ -0,0 +1,3 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
+module c { header "c.h" export * }
diff --git a/clang/test/Modules/merge-anon-in-template.cc b/clang/test/Modules/merge-anon-in-template.cc
new file mode 100644
index 00000000000..6e4e6e09e9c
--- /dev/null
+++ b/clang/test/Modules/merge-anon-in-template.cc
@@ -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;
OpenPOWER on IntegriCloud