[modules] Be sure to load the lexical definition of a class template
specialization from an update record exactly once, even if we needed to fake up
the definition.

llvm-svn: 227939
diff --git a/clang/test/Modules/Inputs/merge-template-members/a.h b/clang/test/Modules/Inputs/merge-template-members/a.h
new file mode 100644
index 0000000..9212a3f
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-template-members/a.h
@@ -0,0 +1,9 @@
+namespace N {
+  template <typename> struct A {
+    int n;
+    A() : n() {}
+  };
+
+  // Create declaration of A<int>.
+  typedef A<int> AI;
+}
diff --git a/clang/test/Modules/Inputs/merge-template-members/b.h b/clang/test/Modules/Inputs/merge-template-members/b.h
new file mode 100644
index 0000000..df537b0
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-template-members/b.h
@@ -0,0 +1,6 @@
+#include "a.h"
+
+// Add update record for definition of A<int> and constructors.
+// We need an eagerly-emitted function here to get the problematic
+// deserialization ordering.
+void foobar() { N::A<int> x; }
diff --git a/clang/test/Modules/Inputs/merge-template-members/c.h b/clang/test/Modules/Inputs/merge-template-members/c.h
new file mode 100644
index 0000000..54f3479
--- /dev/null
+++ b/clang/test/Modules/Inputs/merge-template-members/c.h
@@ -0,0 +1,14 @@
+namespace N {
+  template <typename> struct A {
+    int n;
+    A() : n() {}
+  };
+
+  // Trigger instantiation of definition of A<int>.
+  struct C {
+    A<int> a;
+  };
+}
+
+// Merge in another declaration and update records.
+#include "b.h"
diff --git a/clang/test/Modules/Inputs/merge-template-members/module.modulemap b/clang/test/Modules/Inputs/merge-template-members/module.modulemap
index 9ce5690..280667f 100644
--- a/clang/test/Modules/Inputs/merge-template-members/module.modulemap
+++ b/clang/test/Modules/Inputs/merge-template-members/module.modulemap
@@ -1,2 +1,6 @@
 module def { header "def.h" export * }
 module update { header "update.h" export * }
+
+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-template-members.cpp b/clang/test/Modules/merge-template-members.cpp
index 99696d8..c0bfd2f 100644
--- a/clang/test/Modules/merge-template-members.cpp
+++ b/clang/test/Modules/merge-template-members.cpp
@@ -1,7 +1,10 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/merge-template-members -verify %s
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/merge-template-members -verify -emit-llvm-only %s
 // expected-no-diagnostics
 
+#include "c.h"
+N::A<int> ai;
+
 template<typename> struct A { int n; };
 template<typename> struct B { typedef A<void> C; };
 template class B<int>;