Updated to Clang 3.5a.

Change-Id: I8127eb568f674c2e72635b639a3295381fe8af82
diff --git a/test/Modules/Inputs/ModuleMapLocations/Both/a.h b/test/Modules/Inputs/ModuleMapLocations/Both/a.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Both/a.h
diff --git a/test/Modules/Inputs/ModuleMapLocations/Both/b.h b/test/Modules/Inputs/ModuleMapLocations/Both/b.h
new file mode 100644
index 0000000..3abbd39
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Both/b.h
@@ -0,0 +1 @@
+void wont_be_found1(void);
diff --git a/test/Modules/Inputs/ModuleMapLocations/Both/module.map b/test/Modules/Inputs/ModuleMapLocations/Both/module.map
new file mode 100644
index 0000000..bf5aaed
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Both/module.map
@@ -0,0 +1,3 @@
+module both {
+  header "b.h"
+}
diff --git a/test/Modules/Inputs/ModuleMapLocations/Both/module.modulemap b/test/Modules/Inputs/ModuleMapLocations/Both/module.modulemap
new file mode 100644
index 0000000..0bfa096
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Both/module.modulemap
@@ -0,0 +1,3 @@
+module both {
+  header "a.h"
+}
diff --git a/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/Headers/a.h b/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/Headers/a.h
new file mode 100644
index 0000000..9dabfc0
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/Headers/a.h
@@ -0,0 +1 @@
+void will_be_found2(void);
diff --git a/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/Headers/b.h b/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/Headers/b.h
new file mode 100644
index 0000000..26169fa
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/Headers/b.h
@@ -0,0 +1 @@
+void wont_be_found2(void);
diff --git a/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/Modules/module.modulemap b/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/Modules/module.modulemap
new file mode 100644
index 0000000..da49ba5
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/Modules/module.modulemap
@@ -0,0 +1,3 @@
+framework module Both_F {
+  header "a.h"
+}
diff --git a/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/module.map b/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/module.map
new file mode 100644
index 0000000..8fc108d
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Both_F.framework/module.map
@@ -0,0 +1,3 @@
+framework module Both_F {
+  header "b.h"
+}
diff --git a/test/Modules/Inputs/ModuleMapLocations/Inferred.framework/Headers/Inferred.h b/test/Modules/Inputs/ModuleMapLocations/Inferred.framework/Headers/Inferred.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Inferred.framework/Headers/Inferred.h
diff --git a/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap/a.h b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap/a.h
new file mode 100644
index 0000000..d571c6e
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap/a.h
@@ -0,0 +1 @@
+void will_be_found1(void);
diff --git a/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap/module.modulemap b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap/module.modulemap
new file mode 100644
index 0000000..2ac7cc5
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap/module.modulemap
@@ -0,0 +1,3 @@
+module module_modulemap {
+  header "a.h"
+}
diff --git a/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/Headers/a.h b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/Headers/a.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/Headers/a.h
diff --git a/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/Modules/module.modulemap b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/Modules/module.modulemap
new file mode 100644
index 0000000..400f304
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/Modules/module.modulemap
@@ -0,0 +1,3 @@
+framework module Module_ModuleMap_F {
+  header "a.h"
+}
diff --git a/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/Modules/module.private.modulemap b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/Modules/module.private.modulemap
new file mode 100644
index 0000000..25a469d
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/Modules/module.private.modulemap
@@ -0,0 +1,3 @@
+explicit framework module Module_ModuleMap_F.Private {
+  header "private.h"
+}
diff --git a/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/PrivateHeaders/private.h b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/PrivateHeaders/private.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/Module_ModuleMap_F.framework/PrivateHeaders/private.h
diff --git a/test/Modules/Inputs/ModuleMapLocations/module.modulemap b/test/Modules/Inputs/ModuleMapLocations/module.modulemap
new file mode 100644
index 0000000..a8f5d1f
--- /dev/null
+++ b/test/Modules/Inputs/ModuleMapLocations/module.modulemap
@@ -0,0 +1,2 @@
+framework module * {
+}
diff --git a/test/Modules/Inputs/autolink-sub3.h b/test/Modules/Inputs/autolink-sub3.h
new file mode 100644
index 0000000..132c729
--- /dev/null
+++ b/test/Modules/Inputs/autolink-sub3.h
@@ -0,0 +1 @@
+int autolink_sub3(void);
diff --git a/test/Modules/Inputs/autolink-sub3.pch b/test/Modules/Inputs/autolink-sub3.pch
new file mode 100644
index 0000000..f63b2d5
--- /dev/null
+++ b/test/Modules/Inputs/autolink-sub3.pch
@@ -0,0 +1 @@
+@import autolink.sub3;
diff --git a/test/Modules/Inputs/c-header-bad.h b/test/Modules/Inputs/c-header-bad.h
new file mode 100644
index 0000000..7f7cd87
--- /dev/null
+++ b/test/Modules/Inputs/c-header-bad.h
@@ -0,0 +1,4 @@
+} // expected-error {{extraneous closing brace ('}')}}
+int not_in_extern_c;
+extern "C" { // expected-note {{to match this '{'}}
+// expected-error {{expected '}'}}
diff --git a/test/Modules/Inputs/c-header.h b/test/Modules/Inputs/c-header.h
new file mode 100644
index 0000000..e12f644
--- /dev/null
+++ b/test/Modules/Inputs/c-header.h
@@ -0,0 +1 @@
+int f(void);
diff --git a/test/Modules/Inputs/cxx-header.h b/test/Modules/Inputs/cxx-header.h
new file mode 100644
index 0000000..7ed7775
--- /dev/null
+++ b/test/Modules/Inputs/cxx-header.h
@@ -0,0 +1 @@
+int f();
diff --git a/test/Modules/Inputs/cxx-inline-namespace-b.h b/test/Modules/Inputs/cxx-inline-namespace-b.h
new file mode 100644
index 0000000..242a585
--- /dev/null
+++ b/test/Modules/Inputs/cxx-inline-namespace-b.h
@@ -0,0 +1,5 @@
+@import cxx_inline_namespace;
+
+struct X::Y::Z {
+  void f(struct Elaborated);
+};
diff --git a/test/Modules/Inputs/cxx-inline-namespace.h b/test/Modules/Inputs/cxx-inline-namespace.h
index 2525ad3..4feb850 100644
--- a/test/Modules/Inputs/cxx-inline-namespace.h
+++ b/test/Modules/Inputs/cxx-inline-namespace.h
@@ -9,3 +9,9 @@
     typedef int size_t;
   }
 }
+
+namespace X {
+  inline namespace Y {
+    struct Z;
+  }
+}
diff --git a/test/Modules/Inputs/cxx-irgen-left.h b/test/Modules/Inputs/cxx-irgen-left.h
new file mode 100644
index 0000000..970ac76
--- /dev/null
+++ b/test/Modules/Inputs/cxx-irgen-left.h
@@ -0,0 +1,7 @@
+#include "cxx-irgen-top.h"
+
+S<int> s;
+
+inline int instantiate_min() {
+  return min(1, 2);
+}
diff --git a/test/Modules/Inputs/cxx-irgen-right.h b/test/Modules/Inputs/cxx-irgen-right.h
new file mode 100644
index 0000000..4400c76
--- /dev/null
+++ b/test/Modules/Inputs/cxx-irgen-right.h
@@ -0,0 +1,3 @@
+#include "cxx-irgen-top.h"
+
+inline int h() { return S<int>::f(); }
diff --git a/test/Modules/Inputs/cxx-irgen-top.h b/test/Modules/Inputs/cxx-irgen-top.h
new file mode 100644
index 0000000..8113e94
--- /dev/null
+++ b/test/Modules/Inputs/cxx-irgen-top.h
@@ -0,0 +1,10 @@
+template<typename T> struct S {
+  __attribute__((always_inline)) static int f() { return 0; }
+  __attribute__((always_inline, visibility("hidden"))) static int g() { return 0; }
+};
+
+extern template struct S<int>;
+
+template<typename T> T min(T a, T b) { return a < b ? a : b; }
+
+extern decltype(min(1, 2)) instantiate_min_decl;
diff --git a/test/Modules/Inputs/cxx-templates-a.h b/test/Modules/Inputs/cxx-templates-a.h
index 0b1614d..6ecc2ca 100644
--- a/test/Modules/Inputs/cxx-templates-a.h
+++ b/test/Modules/Inputs/cxx-templates-a.h
@@ -48,3 +48,5 @@
 template<> struct MergeSpecializations<char> {
   typedef int explicitly_specialized_in_a;
 };
+
+void InstantiateWithFriend(Std::WithFriend<int> wfi) {}
diff --git a/test/Modules/Inputs/cxx-templates-b.h b/test/Modules/Inputs/cxx-templates-b.h
index 6cd83fa..a682855 100644
--- a/test/Modules/Inputs/cxx-templates-b.h
+++ b/test/Modules/Inputs/cxx-templates-b.h
@@ -66,4 +66,5 @@
 
 void TriggerInstantiation() {
   UseDefinedInBImpl<void>();
+  Std::f<int>();
 }
diff --git a/test/Modules/Inputs/cxx-templates-common.h b/test/Modules/Inputs/cxx-templates-common.h
index 40a11e2..9b46539 100644
--- a/test/Modules/Inputs/cxx-templates-common.h
+++ b/test/Modules/Inputs/cxx-templates-common.h
@@ -9,3 +9,15 @@
 template<typename T> struct CommonTemplate {
   enum E { a = 1, b = 2, c = 3 };
 };
+
+namespace Std {
+  template<typename T> struct WithFriend {
+    friend bool operator!=(const WithFriend &A, const WithFriend &B) { return false; }
+  };
+}
+
+namespace Std {
+  template<typename T> void f() {
+    extern T g();
+  }
+}
diff --git a/test/Modules/Inputs/declare-use/e.h b/test/Modules/Inputs/declare-use/e.h
index ed8d843..31247f7 100644
--- a/test/Modules/Inputs/declare-use/e.h
+++ b/test/Modules/Inputs/declare-use/e.h
@@ -1,6 +1,7 @@
 #ifndef E_H
 #define E_H
-#include "a.h"
+#define HEADER "a.h"
+#include HEADER
 #include "b.h"
 const int e = a*b;
 #endif
diff --git a/test/Modules/Inputs/declare-use/h.h b/test/Modules/Inputs/declare-use/h.h
index df99a6d..379e501 100644
--- a/test/Modules/Inputs/declare-use/h.h
+++ b/test/Modules/Inputs/declare-use/h.h
@@ -1,7 +1,7 @@
 #ifndef H_H
 #define H_H
 #include "c.h"
-#include "d.h" // expected-error {{use of a module not declared used}}
+#include "d.h" // expected-error {{does not depend on a module exporting}}
 #include "h1.h"
 const int h1 = aux_h*c*7*d;
 #endif
diff --git a/test/Modules/Inputs/declare-use/i.h b/test/Modules/Inputs/declare-use/i.h
new file mode 100644
index 0000000..30e7ded
--- /dev/null
+++ b/test/Modules/Inputs/declare-use/i.h
@@ -0,0 +1 @@
+int aux_i = 13;
diff --git a/test/Modules/Inputs/declare-use/j.h b/test/Modules/Inputs/declare-use/j.h
new file mode 100644
index 0000000..04d46a9
--- /dev/null
+++ b/test/Modules/Inputs/declare-use/j.h
@@ -0,0 +1,14 @@
+#ifndef J_H
+#define J_H
+
+#define STR(x) #x
+#define HDR(x) STR(x.h)
+
+#include ALLOWED_INC
+#include HDR(a)
+
+const int j = a * a + b;
+
+// expected-no-diagnostics
+
+#endif
diff --git a/test/Modules/Inputs/declare-use/module.map b/test/Modules/Inputs/declare-use/module.map
index 774fc37..a176fb3 100644
--- a/test/Modules/Inputs/declare-use/module.map
+++ b/test/Modules/Inputs/declare-use/module.map
@@ -9,21 +9,25 @@
 module XC {
   header "c.h"
   use XA
+  // Intentionally doesn't use XB to show that -fdecl-use isn't transitive.
 }
 
 module XD {
   header "d.h"
   use XA
+  // Intentionally doesn't use XB to show that -fdecl-use isn't transitive.
 }
 
 module XE {
   header "e.h"
+  header "unavailable.h"
   use XA
   use XB
 }
 
 module XF {
   header "f.h"
+  header "unavailable.h"
   use XA
   use XB
 }
@@ -33,11 +37,20 @@
   header "g1.h"
   use XC
   use XE
+  use XJ
 }
 
 module XH {
   header "h.h"
   header "h1.h"
+  header "s.h"
   use XC
   use XE
 }
+
+module XJ {
+  header "j.h"
+}
+
+module XS {
+}
diff --git a/test/Modules/Inputs/declare-use/s.h b/test/Modules/Inputs/declare-use/s.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Modules/Inputs/declare-use/s.h
diff --git a/test/Modules/Inputs/elsewhere/c-header-indirect.h b/test/Modules/Inputs/elsewhere/c-header-indirect.h
new file mode 100644
index 0000000..083c41f
--- /dev/null
+++ b/test/Modules/Inputs/elsewhere/c-header-indirect.h
@@ -0,0 +1 @@
+#include "c-header.h"
diff --git a/test/Modules/Inputs/elsewhere/module.map b/test/Modules/Inputs/elsewhere/module.map
new file mode 100644
index 0000000..2c56820
--- /dev/null
+++ b/test/Modules/Inputs/elsewhere/module.map
@@ -0,0 +1 @@
+module c_library_indirect { header "c-header-indirect.h" }
diff --git a/test/Modules/Inputs/include-relative/a.h b/test/Modules/Inputs/include-relative/a.h
new file mode 100644
index 0000000..b95284b
--- /dev/null
+++ b/test/Modules/Inputs/include-relative/a.h
@@ -0,0 +1 @@
+extern int n;
diff --git a/test/Modules/Inputs/include-relative/module.map b/test/Modules/Inputs/include-relative/module.map
new file mode 100644
index 0000000..bb00c84
--- /dev/null
+++ b/test/Modules/Inputs/include-relative/module.map
@@ -0,0 +1 @@
+module a { header "a.h" }
diff --git a/test/Modules/Inputs/macro-undef-through-pch/A.h b/test/Modules/Inputs/macro-undef-through-pch/A.h
new file mode 100644
index 0000000..6a2cc5c
--- /dev/null
+++ b/test/Modules/Inputs/macro-undef-through-pch/A.h
@@ -0,0 +1,2 @@
+#define AB
+#undef AB
diff --git a/test/Modules/Inputs/macro-undef-through-pch/foo.h b/test/Modules/Inputs/macro-undef-through-pch/foo.h
new file mode 100644
index 0000000..9d0256b
--- /dev/null
+++ b/test/Modules/Inputs/macro-undef-through-pch/foo.h
@@ -0,0 +1 @@
+@import A;
diff --git a/test/Modules/Inputs/macro-undef-through-pch/module.map b/test/Modules/Inputs/macro-undef-through-pch/module.map
new file mode 100644
index 0000000..63f68ca
--- /dev/null
+++ b/test/Modules/Inputs/macro-undef-through-pch/module.map
@@ -0,0 +1,3 @@
+module A {
+  header "A.h"
+}
diff --git a/test/Modules/Inputs/macros_other.h b/test/Modules/Inputs/macros_other.h
index ea686bf..4923a7f 100644
--- a/test/Modules/Inputs/macros_other.h
+++ b/test/Modules/Inputs/macros_other.h
@@ -1 +1,6 @@
-#define OTHER_INTEGER int
+#undef TOP_OTHER_UNDEF1
+#define TOP_OTHER_UNDEF2 42
+#define TOP_OTHER_REDEF1 1
+#define TOP_OTHER_REDEF1 3
+
+#define TOP_OTHER_DEF_RIGHT_UNDEF 4
diff --git a/test/Modules/Inputs/macros_right.h b/test/Modules/Inputs/macros_right.h
index dbbd2c3..a70c350 100644
--- a/test/Modules/Inputs/macros_right.h
+++ b/test/Modules/Inputs/macros_right.h
@@ -17,3 +17,5 @@
 #define TOP_RIGHT_REDEF float
 
 #define FN_ADD(x, y) (x+y)
+
+#undef TOP_OTHER_DEF_RIGHT_UNDEF
diff --git a/test/Modules/Inputs/macros_right_undef.h b/test/Modules/Inputs/macros_right_undef.h
index 49473e3..15a8366 100644
--- a/test/Modules/Inputs/macros_right_undef.h
+++ b/test/Modules/Inputs/macros_right_undef.h
@@ -1 +1,4 @@
 #undef TOP_RIGHT_UNDEF
+
+@import macros_top;
+#undef TOP_OTHER_DEF_RIGHT_UNDEF
diff --git a/test/Modules/Inputs/macros_top.h b/test/Modules/Inputs/macros_top.h
index dd303ff..1093504 100644
--- a/test/Modules/Inputs/macros_top.h
+++ b/test/Modules/Inputs/macros_top.h
@@ -14,3 +14,11 @@
 
 #define TOP_RIGHT_UNDEF int
 
+#define TOP_OTHER_UNDEF1 42
+#undef TOP_OTHER_UNDEF2
+#define TOP_OTHER_REDEF1 1
+#define TOP_OTHER_REDEF2 2
+
+#define TOP_OTHER_DEF_RIGHT_UNDEF void
+
+#define TOP_REDEF_IN_SUBMODULES 0
diff --git a/test/Modules/Inputs/macros_top_b.h b/test/Modules/Inputs/macros_top_b.h
new file mode 100644
index 0000000..cfee17c
--- /dev/null
+++ b/test/Modules/Inputs/macros_top_b.h
@@ -0,0 +1,5 @@
+#include "macros_top.h"
+#undef TOP_REDEF_IN_SUBMODULES
+#define TOP_REDEF_IN_SUBMODULES 1
+#undef TOP_REDEF_IN_SUBMODULES
+#define TOP_REDEF_IN_SUBMODULES 2
diff --git a/test/Modules/Inputs/macros_top_c.h b/test/Modules/Inputs/macros_top_c.h
new file mode 100644
index 0000000..aee8246
--- /dev/null
+++ b/test/Modules/Inputs/macros_top_c.h
@@ -0,0 +1,2 @@
+#include "macros_top_b.h"
+#undef TOP_REDEF_IN_SUBMODULES
diff --git a/test/Modules/Inputs/malformed/a1.h b/test/Modules/Inputs/malformed/a1.h
new file mode 100644
index 0000000..400b916
--- /dev/null
+++ b/test/Modules/Inputs/malformed/a1.h
@@ -0,0 +1 @@
+void f() {
diff --git a/test/Modules/Inputs/malformed/a2.h b/test/Modules/Inputs/malformed/a2.h
new file mode 100644
index 0000000..5c34318
--- /dev/null
+++ b/test/Modules/Inputs/malformed/a2.h
@@ -0,0 +1 @@
+}
diff --git a/test/Modules/Inputs/malformed/b1.h b/test/Modules/Inputs/malformed/b1.h
new file mode 100644
index 0000000..3d98bc1
--- /dev/null
+++ b/test/Modules/Inputs/malformed/b1.h
@@ -0,0 +1,3 @@
+struct S {
+  #include "b2.h"
+};
diff --git a/test/Modules/Inputs/malformed/b2.h b/test/Modules/Inputs/malformed/b2.h
new file mode 100644
index 0000000..7fc5340
--- /dev/null
+++ b/test/Modules/Inputs/malformed/b2.h
@@ -0,0 +1 @@
+void g() {}
diff --git a/test/Modules/Inputs/malformed/module.map b/test/Modules/Inputs/malformed/module.map
new file mode 100644
index 0000000..5277ffa
--- /dev/null
+++ b/test/Modules/Inputs/malformed/module.map
@@ -0,0 +1,8 @@
+module malformed_a {
+  module a1 { header "a1.h" }
+  module a2 { header "a2.h" }
+}
+module malformed_b {
+  module b1 { header "b1.h" }
+  module b2 { header "b2.h" }
+}
diff --git a/test/Modules/Inputs/module.map b/test/Modules/Inputs/module.map
index cf8a298..d6effcf 100644
--- a/test/Modules/Inputs/module.map
+++ b/test/Modules/Inputs/module.map
@@ -1,3 +1,6 @@
+module c_library [extern_c] { module inner { header "c-header.h" } }
+module cxx_library { header "cxx-header.h" requires cplusplus }
+module c_library_bad [extern_c] { header "c-header-bad.h" }
 module diamond_top { header "diamond_top.h" }
 module diamond_left { 
   header "diamond_left.h" 
@@ -12,6 +15,9 @@
   export *
 }
 module irgen { header "irgen.h" }
+module cxx_irgen_top { header "cxx-irgen-top.h" }
+module cxx_irgen_left { header "cxx-irgen-left.h" }
+module cxx_irgen_right { header "cxx-irgen-right.h" }
 module lookup_left_objc { header "lookup_left.h" }
 module lookup_right_objc { header "lookup_right.h" }
 module lookup_left_cxx { header "lookup_left.hpp" }
@@ -20,6 +26,8 @@
 module module_private_right { header "module_private_right.h" }
 module macros_top { 
   header "macros_top.h" 
+  explicit module b { header "macros_top_b.h" }
+  explicit module c { header "macros_top_c.h" }
 }
 module macros_left { 
   header "macros_left.h" 
@@ -33,6 +41,7 @@
   }
 }
 module macros { header "macros.h" }
+module macros_other { header "macros_other.h" }
 module category_top { header "category_top.h" }
 module category_left { 
   header "category_left.h" 
@@ -166,6 +175,11 @@
     header "autolink-sub2.h"
     link framework "autolink_framework"
   }
+
+  explicit module sub3 {
+    header "autolink-sub3.h"
+    link "autolink_from_pch"
+  }
 }
 
 module weird_objc {
@@ -184,6 +198,10 @@
   header "cxx-inline-namespace.h"
 }
 
+module cxx_inline_namespace_b {
+  header "cxx-inline-namespace-b.h"
+}
+
 module cxx_linkage_cache {
   header "cxx-linkage-cache.h"
 }
@@ -281,3 +299,9 @@
 module recursive_visibility_c {
   header "recursive_visibility_c.h"
 }
+module recursive1 {
+  header "recursive1.h"
+}
+module recursive2 {
+  header "recursive2.h"
+}
diff --git a/test/Modules/Inputs/namespaces-left.h b/test/Modules/Inputs/namespaces-left.h
index bd192af..787fe75 100644
--- a/test/Modules/Inputs/namespaces-left.h
+++ b/test/Modules/Inputs/namespaces-left.h
@@ -1,5 +1,18 @@
+namespace RedeclAcrossImport {
+  enum E { e };
+}
+
+namespace AddAndReexportBeforeImport {
+  struct S {};
+  extern struct S t;
+}
+
 @import namespaces_top;
 
+namespace RedeclAcrossImport {
+  E x = e;
+}
+
 float &global(float);
 float &global2(float);
 
diff --git a/test/Modules/Inputs/namespaces-top.h b/test/Modules/Inputs/namespaces-top.h
index 7aa8490..7bf5394 100644
--- a/test/Modules/Inputs/namespaces-top.h
+++ b/test/Modules/Inputs/namespaces-top.h
@@ -17,3 +17,7 @@
   int f(int);
   void (*p)() = &f;
 }
+
+namespace AddAndReexportBeforeImport {
+  int S;
+}
diff --git a/test/Modules/Inputs/recursive1.h b/test/Modules/Inputs/recursive1.h
new file mode 100644
index 0000000..8cb5917
--- /dev/null
+++ b/test/Modules/Inputs/recursive1.h
@@ -0,0 +1 @@
+#include "recursive2.h"
diff --git a/test/Modules/Inputs/recursive2.h b/test/Modules/Inputs/recursive2.h
new file mode 100644
index 0000000..d9480aa
--- /dev/null
+++ b/test/Modules/Inputs/recursive2.h
@@ -0,0 +1 @@
+#include "recursive1.h"
diff --git a/test/Modules/Inputs/string_names/a.h b/test/Modules/Inputs/string_names/a.h
new file mode 100644
index 0000000..a36dc1b
--- /dev/null
+++ b/test/Modules/Inputs/string_names/a.h
@@ -0,0 +1,4 @@
+#ifndef A_H
+#define A_H
+const int a = 2;
+#endif
diff --git a/test/Modules/Inputs/string_names/b.h b/test/Modules/Inputs/string_names/b.h
new file mode 100644
index 0000000..55daf72
--- /dev/null
+++ b/test/Modules/Inputs/string_names/b.h
@@ -0,0 +1,4 @@
+#ifndef B_H
+#define B_H
+const int b = 3;
+#endif
diff --git a/test/Modules/Inputs/string_names/c.h b/test/Modules/Inputs/string_names/c.h
new file mode 100644
index 0000000..38c278f
--- /dev/null
+++ b/test/Modules/Inputs/string_names/c.h
@@ -0,0 +1,4 @@
+#ifndef C_H
+#define C_H
+const int c = 2;
+#endif
diff --git a/test/Modules/Inputs/string_names/module.map b/test/Modules/Inputs/string_names/module.map
new file mode 100644
index 0000000..4e70eda
--- /dev/null
+++ b/test/Modules/Inputs/string_names/module.map
@@ -0,0 +1,16 @@
+module "my/module-a" {
+  header "a.h"
+  use "my/module-c"
+
+  module "Sub" {
+    header "sub.h"
+  }
+}
+
+module "my/module-b" {
+  header "b.h"
+}
+
+module "my/module-c" {
+  header "c.h"
+}
diff --git a/test/Modules/Inputs/string_names/sub.h b/test/Modules/Inputs/string_names/sub.h
new file mode 100644
index 0000000..64b9112
--- /dev/null
+++ b/test/Modules/Inputs/string_names/sub.h
@@ -0,0 +1,4 @@
+#ifndef SUB_H
+#define SUB_H
+const int sub = 2;
+#endif
diff --git a/test/Modules/Inputs/submodules/import-self-b.h b/test/Modules/Inputs/submodules/import-self-b.h
index f88b56d..9852094 100644
--- a/test/Modules/Inputs/submodules/import-self-b.h
+++ b/test/Modules/Inputs/submodules/import-self-b.h
@@ -1,10 +1,12 @@
+// FIXME: This import has no effect, because the submodule isn't built yet, and
+// we don't map an @import to a #include in this case.
 @import import_self.c;
 #include "import-self-d.h"
 
 // FIXME: This should not work; names from 'a' should not be visible here.
 MyTypeA import_self_test_a;
 
-// FIXME: This should work but does not; names from 'b' are not actually visible here.
+// FIXME: This should work but does not; names from 'c' are not actually visible here.
 //MyTypeC import_self_test_c;
 
 MyTypeD import_self_test_d;
diff --git a/test/Modules/Inputs/submodules/module.map b/test/Modules/Inputs/submodules/module.map
index c91e94f..1593103 100644
--- a/test/Modules/Inputs/submodules/module.map
+++ b/test/Modules/Inputs/submodules/module.map
@@ -10,3 +10,8 @@
   module c { header "import-self-c.h" }
   module d { header "import-self-d.h" }
 }
+
+module missing_headers {
+  module missing { header "missing.h" }
+  module not_missing { header "not_missing.h" }
+}
diff --git a/test/Modules/Inputs/submodules/not_missing.h b/test/Modules/Inputs/submodules/not_missing.h
new file mode 100644
index 0000000..1f8d048
--- /dev/null
+++ b/test/Modules/Inputs/submodules/not_missing.h
@@ -0,0 +1,2 @@
+void NotMissingFunction() {
+}
diff --git a/test/Modules/Inputs/template-specialization-visibility/a.h b/test/Modules/Inputs/template-specialization-visibility/a.h
new file mode 100644
index 0000000..e8820555
--- /dev/null
+++ b/test/Modules/Inputs/template-specialization-visibility/a.h
@@ -0,0 +1,8 @@
+#ifndef A_H
+#define A_H
+template<typename T> struct S;
+template<typename U> struct T {
+  struct S;
+  enum E : int;
+};
+#endif
diff --git a/test/Modules/Inputs/template-specialization-visibility/b.h b/test/Modules/Inputs/template-specialization-visibility/b.h
new file mode 100644
index 0000000..1a09826
--- /dev/null
+++ b/test/Modules/Inputs/template-specialization-visibility/b.h
@@ -0,0 +1,7 @@
+#ifndef B_H
+#define B_H
+#include "a.h"
+S<int> *s1;
+T<int>::S *s2;
+T<int>::E e1;
+#endif
diff --git a/test/Modules/Inputs/template-specialization-visibility/c.h b/test/Modules/Inputs/template-specialization-visibility/c.h
new file mode 100644
index 0000000..a92fb3b
--- /dev/null
+++ b/test/Modules/Inputs/template-specialization-visibility/c.h
@@ -0,0 +1,6 @@
+#ifndef C_H
+#define C_H
+template<typename T> struct S { int n; };
+template<typename U> struct T<U>::S { int n; };
+template<typename U> enum T<U>::E : int { e };
+#endif
diff --git a/test/Modules/Inputs/template-specialization-visibility/d.h b/test/Modules/Inputs/template-specialization-visibility/d.h
new file mode 100644
index 0000000..3048272
--- /dev/null
+++ b/test/Modules/Inputs/template-specialization-visibility/d.h
@@ -0,0 +1,5 @@
+#ifndef D_H
+#define D_H
+template<typename> struct S;
+template<typename> struct T;
+#endif
diff --git a/test/Modules/Inputs/template-specialization-visibility/e.h b/test/Modules/Inputs/template-specialization-visibility/e.h
new file mode 100644
index 0000000..5d6b142
--- /dev/null
+++ b/test/Modules/Inputs/template-specialization-visibility/e.h
@@ -0,0 +1,6 @@
+#ifndef E_H
+#define E_H
+#include "c.h"
+template struct S<char>;
+template struct T<char>;
+#endif
diff --git a/test/Modules/Inputs/template-specialization-visibility/module.map b/test/Modules/Inputs/template-specialization-visibility/module.map
new file mode 100644
index 0000000..f0e2a0e
--- /dev/null
+++ b/test/Modules/Inputs/template-specialization-visibility/module.map
@@ -0,0 +1,7 @@
+module tsv {
+  module a { header "a.h" }
+  module b { header "b.h" }
+  module c { header "c.h" }
+  module d { header "d.h" }
+  module e { header "e.h" }
+}
diff --git a/test/Modules/Inputs/unnecessary-module-map-parsing/a1.h b/test/Modules/Inputs/unnecessary-module-map-parsing/a1.h
new file mode 100644
index 0000000..56757a7
--- /dev/null
+++ b/test/Modules/Inputs/unnecessary-module-map-parsing/a1.h
@@ -0,0 +1 @@
+void f() {}
diff --git a/test/Modules/Inputs/unnecessary-module-map-parsing/module.map b/test/Modules/Inputs/unnecessary-module-map-parsing/module.map
new file mode 100644
index 0000000..6d4ceee
--- /dev/null
+++ b/test/Modules/Inputs/unnecessary-module-map-parsing/module.map
@@ -0,0 +1,3 @@
+module a {
+  eader "unknown.h"
+}
diff --git a/test/Modules/Inputs/update-after-load/a.h b/test/Modules/Inputs/update-after-load/a.h
new file mode 100644
index 0000000..0ebcf3e
--- /dev/null
+++ b/test/Modules/Inputs/update-after-load/a.h
@@ -0,0 +1 @@
+namespace llvm {}
diff --git a/test/Modules/Inputs/update-after-load/b.h b/test/Modules/Inputs/update-after-load/b.h
new file mode 100644
index 0000000..64e9bfd
--- /dev/null
+++ b/test/Modules/Inputs/update-after-load/b.h
@@ -0,0 +1,2 @@
+#include "a.h"
+namespace llvm { void f(); }
diff --git a/test/Modules/Inputs/update-after-load/module.map b/test/Modules/Inputs/update-after-load/module.map
new file mode 100644
index 0000000..21e160e
--- /dev/null
+++ b/test/Modules/Inputs/update-after-load/module.map
@@ -0,0 +1 @@
+module a { header "a.h" } module b { header "b.h" }
diff --git a/test/Modules/Inputs/update-after-load/modules.timestamp b/test/Modules/Inputs/update-after-load/modules.timestamp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Modules/Inputs/update-after-load/modules.timestamp
diff --git a/test/Modules/auto-module-import.m b/test/Modules/auto-module-import.m
index d7fb9d1..bf99377 100644
--- a/test/Modules/auto-module-import.m
+++ b/test/Modules/auto-module-import.m
@@ -83,6 +83,6 @@
   return not_in_module;
 }
 
-void includeNotAtTopLevel() {
-  #include <NoUmbrella/A.h> // expected-warning {{treating #include as an import}} expected-error {{expected expression}}
-}
+void includeNotAtTopLevel() { // expected-note {{to match this '{'}}
+  #include <NoUmbrella/A.h> // expected-warning {{treating #include as an import}} expected-error {{expected '}'}}
+} // expected-error {{extraneous closing brace}}
diff --git a/test/Modules/autolink.m b/test/Modules/autolink.m
index 077aac5..883a2f5 100644
--- a/test/Modules/autolink.m
+++ b/test/Modules/autolink.m
@@ -1,6 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -emit-llvm -o - -fmodules-cache-path=%t -fmodules -F %S/Inputs -I %S/Inputs %s | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm -fno-autolink -o - -fmodules-cache-path=%t -fmodules -F %S/Inputs -I %S/Inputs %s | FileCheck --check-prefix=CHECK-AUTOLINK-DISABLED %s
+// RUN: %clang_cc1 -emit-pch -fmodules-cache-path=%t -fmodules -o %t.pch -I %S/Inputs -x objective-c-header %S/Inputs/autolink-sub3.pch
+// RUN: %clang_cc1 -emit-llvm -o - -fmodules-cache-path=%t -fmodules -F %S/Inputs -I %S/Inputs -include-pch %t.pch %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -fno-autolink -o - -fmodules-cache-path=%t -fmodules -F %S/Inputs -I %S/Inputs -include-pch %t.pch %s | FileCheck --check-prefix=CHECK-AUTOLINK-DISABLED %s
 
 @import autolink.sub2;
 
@@ -29,11 +30,16 @@
   return no_umbrella_A;
 }
 
+int use_autolink_sub3() {
+  return autolink_sub3();
+}
+
 // NOTE: "autolink_sub" is intentionally not linked.
 
 // CHECK: !llvm.module.flags = !{!0, !1, !2, !3, !4}
 // CHECK: !4 = metadata !{i32 6, metadata !"Linker Options", metadata ![[AUTOLINK_OPTIONS:[0-9]+]]}
-// CHECK: ![[AUTOLINK_OPTIONS]] = metadata !{metadata ![[AUTOLINK_FRAMEWORK:[0-9]+]], metadata ![[AUTOLINK:[0-9]+]], metadata ![[DEPENDSONMODULE:[0-9]+]], metadata ![[MODULE:[0-9]+]], metadata ![[NOUMBRELLA:[0-9]+]]}
+// CHECK: ![[AUTOLINK_OPTIONS]] = metadata !{metadata ![[AUTOLINK_PCH:[0-9]+]], metadata ![[AUTOLINK_FRAMEWORK:[0-9]+]], metadata ![[AUTOLINK:[0-9]+]], metadata ![[DEPENDSONMODULE:[0-9]+]], metadata ![[MODULE:[0-9]+]], metadata ![[NOUMBRELLA:[0-9]+]]}
+// CHECK: ![[AUTOLINK_PCH]] = metadata !{metadata !"{{(-l|/DEFAULTLIB:)}}autolink_from_pch{{(\.lib)?}}"}
 // CHECK: ![[AUTOLINK_FRAMEWORK]] = metadata !{metadata !"-framework", metadata !"autolink_framework"}
 // CHECK: ![[AUTOLINK]] = metadata !{metadata !"{{(-l|/DEFAULTLIB:)}}autolink{{(\.lib)?}}"}
 // CHECK: ![[DEPENDSONMODULE]] = metadata !{metadata !"-framework", metadata !"DependsOnModule"}
diff --git a/test/Modules/config_macros.m b/test/Modules/config_macros.m
index 200744d..b147317 100644
--- a/test/Modules/config_macros.m
+++ b/test/Modules/config_macros.m
@@ -24,5 +24,5 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -DWANT_FOO=1 -emit-module -fmodule-name=config %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -DWANT_FOO=1 %s -verify
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -DWANT_FOO=1 %s -verify
 
diff --git a/test/Modules/cxx-inline-namespace.cpp b/test/Modules/cxx-inline-namespace.cpp
index 5b96790..f67d43b 100644
--- a/test/Modules/cxx-inline-namespace.cpp
+++ b/test/Modules/cxx-inline-namespace.cpp
@@ -2,5 +2,8 @@
 // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11
 
 @import cxx_inline_namespace;
+@import cxx_inline_namespace_b;
 
 T x; // expected-error {{unknown type name 'T'}}
+
+X::Elaborated *p;
diff --git a/test/Modules/cxx-irgen.cpp b/test/Modules/cxx-irgen.cpp
new file mode 100644
index 0000000..7a42cb6
--- /dev/null
+++ b/test/Modules/cxx-irgen.cpp
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -x objective-c++ -std=c++11 -fmodules-cache-path=%t -I %S/Inputs -triple %itanium_abi_triple -disable-llvm-optzns -emit-llvm -o - %s | FileCheck %s
+// FIXME: When we have a syntax for modules in C++, use that.
+
+@import cxx_irgen_top;
+@import cxx_irgen_left;
+@import cxx_irgen_right;
+
+// CHECK-DAG: define available_externally hidden i32 @_ZN1SIiE1gEv({{.*}} #[[ALWAYS_INLINE:.*]] align
+int a = S<int>::g();
+
+// CHECK-DAG: define available_externally i32 @_ZN1SIiE1fEv({{.*}} #[[ALWAYS_INLINE]] align
+int b = h();
+
+// CHECK-DAG: define linkonce_odr i32 @_Z3minIiET_S0_S0_(i32
+int c = min(1, 2);
+
+// CHECK: attributes #[[ALWAYS_INLINE]] = {{.*}} alwaysinline
diff --git a/test/Modules/cxx-templates.cpp b/test/Modules/cxx-templates.cpp
index 65f41f6..291fabf 100644
--- a/test/Modules/cxx-templates.cpp
+++ b/test/Modules/cxx-templates.cpp
@@ -1,6 +1,7 @@
 // RUN: rm -rf %t
 // RUN: not %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups | FileCheck %s --check-prefix=CHECK-GLOBAL
 // RUN: not %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups -ast-dump-filter N | FileCheck %s --check-prefix=CHECK-NAMESPACE-N
+// RUN: not %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump | FileCheck %s --check-prefix=CHECK-DUMP
 // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11
 
 @import cxx_templates_a;
@@ -116,10 +117,37 @@
   c = d;
 }
 
+bool testFriendInClassTemplate(Std::WithFriend<int> wfi) {
+  return wfi != wfi;
+}
+
+namespace Std {
+  void g(); // expected-error {{functions that differ only in their return type cannot be overloaded}}
+  // expected-note@cxx-templates-common.h:21 {{previous}}
+}
+
+// FIXME: We should only have two entries for each of these names (one for each
+// function template), but we don't attempt to deduplicate lookup results from
+// sibling modules yet.
+
 // CHECK-GLOBAL:      DeclarationName 'f'
 // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
 // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f'
 
 // CHECK-NAMESPACE-N:      DeclarationName 'f'
 // CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
 // CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f'
+
+// CHECK-DUMP:      ClassTemplateDecl {{.*}} <{{.*[/\\]}}cxx-templates-common.h:1:1, {{.*}}>  col:{{.*}} in cxx_templates_common SomeTemplate
+// CHECK-DUMP:        ClassTemplateSpecializationDecl {{.*}} prev [[CHAR2:[^ ]*]] {{.*}} SomeTemplate
+// CHECK-DUMP-NEXT:     TemplateArgument type 'char [2]'
+// CHECK-DUMP:        ClassTemplateSpecializationDecl [[CHAR2]] {{.*}} SomeTemplate definition
+// CHECK-DUMP-NEXT:     TemplateArgument type 'char [2]'
+// CHECK-DUMP:        ClassTemplateSpecializationDecl {{.*}} prev [[CHAR1:[^ ]*]] {{.*}} SomeTemplate
+// CHECK-DUMP-NEXT:     TemplateArgument type 'char [1]'
+// CHECK-DUMP:        ClassTemplateSpecializationDecl [[CHAR1]] {{.*}} SomeTemplate definition
+// CHECK-DUMP-NEXT:     TemplateArgument type 'char [1]'
diff --git a/test/Modules/declare-use.S b/test/Modules/declare-use.S
new file mode 100644
index 0000000..2c5d8af
--- /dev/null
+++ b/test/Modules/declare-use.S
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang -fmodule-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=XS -I %S/Inputs/declare-use -S %s -Xclang -verify
+// expected-no-diagnostics
+
+#include "s.h"
diff --git a/test/Modules/declare-use1.cpp b/test/Modules/declare-use1.cpp
index 4508017..5fc4336 100644
--- a/test/Modules/declare-use1.cpp
+++ b/test/Modules/declare-use1.cpp
@@ -1,7 +1,8 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -x objective-c++ -fmodules-cache-path=%t -fmodules -fmodules-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify
+// RUN: %clang_cc1 -fmodule-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify
 
 #include "g.h"
 #include "e.h"
-#include "f.h" // expected-error {{use of a module not declared used}}
-const int g2 = g1+e+f;
+#include "f.h" // expected-error {{module XG does not depend on a module exporting 'f.h'}}
+#include "i.h"
+const int g2 = g1 + e + f + aux_i;
diff --git a/test/Modules/declare-use2.cpp b/test/Modules/declare-use2.cpp
index a2ec55e..4535289 100644
--- a/test/Modules/declare-use2.cpp
+++ b/test/Modules/declare-use2.cpp
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -x objective-c++ -fmodules-cache-path=%t -fmodules -fmodules-decluse -fmodule-name=XH -I %S/Inputs/declare-use %s -verify
+// RUN: %clang_cc1 -fmodule-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=XH -I %S/Inputs/declare-use %s -verify
 
 #include "h.h"
 #include "e.h"
-#include "f.h" // expected-error {{use of a module not declared used}}
+#include "f.h" // expected-error {{module XH does not depend on a module exporting 'f.h'}}
 const int h2 = h1+e+f;
diff --git a/test/Modules/declare-use3.cpp b/test/Modules/declare-use3.cpp
new file mode 100644
index 0000000..8b0bbfa
--- /dev/null
+++ b/test/Modules/declare-use3.cpp
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -include "g.h" -include "e.h" -include "f.h" -include "i.h" -fmodule-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify
+// expected-error {{module XG does not depend on a module exporting 'f.h'}}
+const int g2 = g1 + e + f + aux_i;
diff --git a/test/Modules/declare-use4.cpp b/test/Modules/declare-use4.cpp
new file mode 100644
index 0000000..1d34646
--- /dev/null
+++ b/test/Modules/declare-use4.cpp
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodule-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify
+
+#define ALLOWED_INC "b.h"
+
+#include "j.h"
+
+const int g2 = j;
+
+// expected-no-diagnostics
diff --git a/test/Modules/dependency-gen-inferred-map.m b/test/Modules/dependency-gen-inferred-map.m
new file mode 100644
index 0000000..11cc872
--- /dev/null
+++ b/test/Modules/dependency-gen-inferred-map.m
@@ -0,0 +1,8 @@
+// Test that the virtual file "__inferred_module.map" doesn't show up as dependency.
+
+// RUN: rm -rf %t-mcp
+// RUN: %clang_cc1 -isysroot %S/Inputs/System -triple x86_64-apple-darwin10 -dependency-file %t.d -MT %s.o -F %S/Inputs -fsyntax-only -fmodules -fmodules-cache-path=%t-mcp %s
+// RUN: FileCheck %s < %t.d
+// CHECK-NOT: __inferred_module
+
+@import Module;
diff --git a/test/Modules/dependency-gen-pch.m b/test/Modules/dependency-gen-pch.m
new file mode 100644
index 0000000..b0c7551
--- /dev/null
+++ b/test/Modules/dependency-gen-pch.m
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t-mcp
+// RUN: mkdir -p %t-mcp
+
+// RUN: %clang_cc1 -isysroot %S/Inputs/System -triple x86_64-apple-darwin10 -module-file-deps -dependency-file %t.d -MT %s.o -I %S/Inputs -fmodules -fmodules-cache-path=%t-mcp -emit-pch -o %t.pch %s
+// RUN: FileCheck %s < %t.d
+// CHECK: dependency-gen-pch.m.o
+// CHECK-NEXT: dependency-gen-pch.m
+// CHECK-NEXT: diamond_top.pcm
+// CHECK-NEXT: Inputs{{.}}diamond_top.h
+// CHECK-NEXT: Inputs{{.}}module.map
+
+#import "diamond_top.h"
diff --git a/test/Modules/dependency-gen.m b/test/Modules/dependency-gen.m
new file mode 100644
index 0000000..dec8384
--- /dev/null
+++ b/test/Modules/dependency-gen.m
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t-mcp
+// RUN: mkdir -p %t-mcp
+
+// RUN: %clang_cc1 -x objective-c -isysroot %S/Inputs/System -triple x86_64-apple-darwin10 -dependency-file %t.d.1 -MT %s.o -I %S/Inputs -fsyntax-only -fmodules -fmodules-cache-path=%t-mcp %s
+// RUN: FileCheck %s < %t.d.1
+// CHECK: dependency-gen.m
+// CHECK: Inputs{{.}}diamond_top.h
+// CHECK: Inputs{{.}}module.map
+// CHECK-NOT: usr{{.}}include{{.}}module.map
+// CHECK-NOT: stdint.h
+
+
+// RUN: %clang_cc1 -x objective-c -isysroot %S/Inputs/System -triple x86_64-apple-darwin10 -dependency-file %t.d.2 -MT %s.o -I %S/Inputs -sys-header-deps -fsyntax-only -fmodules -fmodules-cache-path=%t-mcp %s
+// RUN: FileCheck %s -check-prefix=CHECK-SYS < %t.d.2
+// CHECK-SYS: dependency-gen.m
+// CHECK-SYS: Inputs{{.}}diamond_top.h
+// CHECK-SYS: Inputs{{.}}module.map
+// CHECK-SYS: usr{{.}}include{{.}}module.map
+// CHECK-SYS: stdint.h
+
+#import "diamond_top.h"
+#import "stdint.h" // inside sysroot
diff --git a/test/Modules/diag-pragma.c b/test/Modules/diag-pragma.c
index 7ec3400..89435c1 100644
--- a/test/Modules/diag-pragma.c
+++ b/test/Modules/diag-pragma.c
@@ -1,6 +1,6 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=diag_pragma %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t %s
+// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s
 // FIXME: When we have a syntax for modules in C, use that.
 
 @import diag_pragma;
diff --git a/test/Modules/diamond-pch.c b/test/Modules/diamond-pch.c
index e7ad02d..37a8cbe 100644
--- a/test/Modules/diamond-pch.c
+++ b/test/Modules/diamond-pch.c
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=diamond_left %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=diamond_right %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=diamond_bottom %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -x objective-c -emit-pch -fmodules-cache-path=%t -o %t.pch %S/Inputs/diamond.h
+// RUN: %clang_cc1 -fmodules -x objective-c -emit-pch -fmodules-cache-path=%t -I %S/Inputs -o %t.pch %S/Inputs/diamond.h
 // RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -include-pch %t.pch %s -verify
 // FIXME: When we have a syntax for modules in C, use that.
 
diff --git a/test/Modules/diamond.c b/test/Modules/diamond.c
index 89d5bc0..8b82408 100644
--- a/test/Modules/diamond.c
+++ b/test/Modules/diamond.c
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=diamond_left %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=diamond_right %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=diamond_bottom %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t %s -verify
+// RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s -verify
 // FIXME: When we have a syntax for modules in C, use that.
 
 @import diamond_bottom;
diff --git a/test/Modules/extern_c.cpp b/test/Modules/extern_c.cpp
new file mode 100644
index 0000000..ba466f2
--- /dev/null
+++ b/test/Modules/extern_c.cpp
@@ -0,0 +1,81 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DEXTERN_C
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DEXTERN_CXX
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DEXTERN_C -DEXTERN_CXX
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DEXTERN_C -DNAMESPACE
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DCXX_HEADER
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DCXX_HEADER -DEXTERN_C
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DCXX_HEADER -DEXTERN_CXX
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DCXX_HEADER -DEXTERN_C -DEXTERN_CXX
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs %s -DCXX_HEADER -DEXTERN_C -DNAMESPACE
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs -x c %s
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/elsewhere -I %S/Inputs %s -DEXTERN_C -DINDIRECT
+
+#ifdef INDIRECT
+#include "c-header-indirect.h"
+#endif
+
+#ifdef NAMESPACE
+namespace M {
+#endif
+
+#ifdef EXTERN_C
+extern "C" {
+#endif
+
+#ifdef EXTERN_CXX
+extern "C++" {
+#endif
+
+#ifdef CXX_HEADER
+#define HEADER "cxx-header.h"
+#else
+#define HEADER "c-header.h"
+#endif
+
+#include HEADER
+
+#if defined(EXTERN_C) && !defined(EXTERN_CXX) && defined(CXX_HEADER)
+// expected-error@-3 {{import of C++ module 'cxx_library' appears within extern "C" language linkage specification}}
+// expected-note@-17 {{extern "C" language linkage specification begins here}}
+#elif defined(NAMESPACE)
+// expected-error-re@-6 {{import of module '{{c_library.inner|cxx_library}}' appears within namespace 'M'}}
+// expected-note@-24 {{namespace 'M' begins here}}
+#endif
+
+#ifdef EXTERN_CXX
+}
+#endif
+
+#ifdef EXTERN_C
+}
+#endif
+
+#ifdef NAMESPACE
+}
+using namespace M;
+#endif
+
+#ifdef __cplusplus
+namespace N {
+#endif
+  void g() {
+    int k = f();
+  }
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+    int f;
+#if !defined(CXX_HEADER)
+    // expected-error@-2 {{redefinition of 'f' as different kind of symbol}}
+    // expected-note@c-header.h:1 {{previous}}
+#endif
+
+#ifdef __cplusplus
+  }
+}
+#endif
+
+suppress_expected_no_diagnostics_error error_here; // expected-error {{}}
diff --git a/test/Modules/extern_c_bad.cpp b/test/Modules/extern_c_bad.cpp
new file mode 100644
index 0000000..bafdc04
--- /dev/null
+++ b/test/Modules/extern_c_bad.cpp
@@ -0,0 +1,2 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -verify -fmodules -x c++ -emit-module -fmodules-cache-path=%t -fmodule-name=c_library_bad %S/Inputs/module.map
diff --git a/test/Modules/fatal-module-loader-error.m b/test/Modules/fatal-module-loader-error.m
index 6af3b4c..2d8dd24 100644
--- a/test/Modules/fatal-module-loader-error.m
+++ b/test/Modules/fatal-module-loader-error.m
@@ -23,4 +23,4 @@
 // Also check that libclang does not create a PCH with such an error.
 // RUN: not c-index-test -write-pch %t.pch -fmodules -fmodules-cache-path=%t \
 // RUN: %s -Xclang -fdisable-module-hash -F %S/Inputs 2>&1 | FileCheck %s
-// CHECK: Unable to write PCH file
+// CHECK: {{^}}Failure: AST deserialization error occurred{{$}}
diff --git a/test/Modules/fmodules-validate-once-per-build-session.c b/test/Modules/fmodules-validate-once-per-build-session.c
new file mode 100644
index 0000000..346d5a7
--- /dev/null
+++ b/test/Modules/fmodules-validate-once-per-build-session.c
@@ -0,0 +1,45 @@
+#include "foo.h"
+
+// Clear the module cache.
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/Inputs
+// RUN: mkdir -p %t/modules-to-compare
+
+// ===
+// Create a module with system headers.
+// RUN: echo 'void meow(void);' > %t/Inputs/foo.h
+// RUN: echo 'module Foo [system] { header "foo.h" }' > %t/Inputs/module.map
+
+// ===
+// Compile the module.
+// RUN: %clang_cc1 -cc1 -fmodules -fdisable-module-hash -fmodules-cache-path=%t/modules-cache -fsyntax-only -I %t/Inputs -fbuild-session-timestamp=1390000000 -fmodules-validate-once-per-build-session %s
+// RUN: ls -R %t/modules-cache | grep Foo.pcm.timestamp
+// RUN: cp %t/modules-cache/Foo.pcm %t/modules-to-compare/Foo-before.pcm
+
+// ===
+// Use it, and make sure that we did not recompile it.
+// RUN: %clang_cc1 -cc1 -fmodules -fdisable-module-hash -fmodules-cache-path=%t/modules-cache -fsyntax-only -I %t/Inputs -fbuild-session-timestamp=1390000000 -fmodules-validate-once-per-build-session %s
+// RUN: ls -R %t/modules-cache | grep Foo.pcm.timestamp
+// RUN: cp %t/modules-cache/Foo.pcm %t/modules-to-compare/Foo-after.pcm
+
+// RUN: diff %t/modules-to-compare/Foo-before.pcm %t/modules-to-compare/Foo-after.pcm
+
+// ===
+// Change the sources.
+// RUN: echo 'void meow2(void);' > %t/Inputs/foo.h
+
+// ===
+// Use the module, and make sure that we did not recompile it, even though the sources changed.
+// RUN: %clang_cc1 -cc1 -fmodules -fdisable-module-hash -fmodules-cache-path=%t/modules-cache -fsyntax-only -I %t/Inputs -fbuild-session-timestamp=1390000000 -fmodules-validate-once-per-build-session %s
+// RUN: ls -R %t/modules-cache | grep Foo.pcm.timestamp
+// RUN: cp %t/modules-cache/Foo.pcm %t/modules-to-compare/Foo-after.pcm
+
+// RUN: diff %t/modules-to-compare/Foo-before.pcm %t/modules-to-compare/Foo-after.pcm
+
+// ===
+// Recompile the module if the today's date is before 01 January 2030.
+// RUN: %clang_cc1 -cc1 -fmodules -fdisable-module-hash -fmodules-cache-path=%t/modules-cache -fsyntax-only -I %t/Inputs -fbuild-session-timestamp=1893456000 -fmodules-validate-once-per-build-session %s
+// RUN: ls -R %t/modules-cache | grep Foo.pcm.timestamp
+// RUN: cp %t/modules-cache/Foo.pcm %t/modules-to-compare/Foo-after.pcm
+
+// RUN: not diff %t/modules-to-compare/Foo-before.pcm %t/modules-to-compare/Foo-after.pcm
diff --git a/test/Modules/include-relative.c b/test/Modules/include-relative.c
new file mode 100644
index 0000000..9ca76ee
--- /dev/null
+++ b/test/Modules/include-relative.c
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: cp -r %S/Inputs/include-relative %t/include-relative
+// RUN: cd %t
+// RUN: %clang_cc1 -fmodules -x c -verify -fmodules-cache-path=%t -I include-relative %s
+// REQUIRES: shell
+
+// expected-no-diagnostics
+
+#include "a.h"
+
+int f() { return n; }
diff --git a/test/Modules/irgen.c b/test/Modules/irgen.c
index 9a7cf7e..c44afb1 100644
--- a/test/Modules/irgen.c
+++ b/test/Modules/irgen.c
@@ -1,6 +1,6 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -emit-module -fmodule-name=irgen -triple x86_64-apple-darwin10 %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -I %S/Inputs -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
 // FIXME: When we have a syntax for modules in C, use that.
 
 @import irgen;
diff --git a/test/Modules/linkage-merge.cpp b/test/Modules/linkage-merge.cpp
index 9cc9ae6..664716d 100644
--- a/test/Modules/linkage-merge.cpp
+++ b/test/Modules/linkage-merge.cpp
@@ -7,6 +7,5 @@
 int f(int);
 
 static void g(int);
-// expected-error@-1 {{declaration conflicts with target of using declaration already in scope}}
-// expected-note@Inputs/linkage-merge-foo.h:2 {{target of using declaration}}
-// expected-note@Inputs/linkage-merge-bar.h:3 {{using declaration}}
+// expected-error@-1 {{functions that differ only in their return type cannot be overloaded}}
+// expected-note@Inputs/linkage-merge-foo.h:2 {{previous declaration is here}}
diff --git a/test/Modules/linkage-merge.m b/test/Modules/linkage-merge.m
index e838ca1..12ad32f 100644
--- a/test/Modules/linkage-merge.m
+++ b/test/Modules/linkage-merge.m
@@ -1,6 +1,6 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -emit-module -fmodule-name=linkage_merge_left %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -w %s -verify
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -w %s -verify
 
 // Test redeclarations of functions where the original declaration is
 // still hidden.
diff --git a/test/Modules/load_failure.c b/test/Modules/load_failure.c
index 6c6d812..8b0d202 100644
--- a/test/Modules/load_failure.c
+++ b/test/Modules/load_failure.c
@@ -8,10 +8,10 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -fdisable-module-hash -emit-module -fmodule-name=load_failure %S/Inputs/module.map
-// RUN: not %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -fdisable-module-hash %s -DNONEXISTENT 2>&1 | FileCheck -check-prefix=CHECK-NONEXISTENT %s
+// RUN: not %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -I %S/Inputs -fdisable-module-hash %s -DNONEXISTENT 2>&1 | FileCheck -check-prefix=CHECK-NONEXISTENT %s
 // CHECK-NONEXISTENT: load_failure.c:2:9: fatal error: module 'load_nonexistent' not found
 
-// RUN: not %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -fdisable-module-hash %s -DFAILURE 2> %t.out
+// RUN: not %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -I %S/Inputs -fdisable-module-hash %s -DFAILURE 2> %t.out
 // RUN: FileCheck -check-prefix=CHECK-FAILURE %s < %t.out
 
 // FIXME: Clean up diagnostic text below and give it a location
diff --git a/test/Modules/lookup.cpp b/test/Modules/lookup.cpp
index efd88f4..bfe0307 100644
--- a/test/Modules/lookup.cpp
+++ b/test/Modules/lookup.cpp
@@ -26,8 +26,8 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c++ -emit-module -fmodules-cache-path=%t -fmodule-name=lookup_left_cxx %S/Inputs/module.map -verify
 // RUN: %clang_cc1 -fmodules -x objective-c++ -emit-module -fmodules-cache-path=%t -fmodule-name=lookup_right_cxx %S/Inputs/module.map -verify
-// RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t %s -verify
-// RUN: %clang_cc1 -fmodules -ast-print -x objective-c++ -fmodules-cache-path=%t %s | FileCheck -check-prefix=CHECK-PRINT %s
+// RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s -verify
+// RUN: %clang_cc1 -fmodules -ast-print -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix=CHECK-PRINT %s
 // FIXME: When we have a syntax for modules in C++, use that.
 
 // CHECK-PRINT: int *f0(int *);
diff --git a/test/Modules/lookup.m b/test/Modules/lookup.m
index 54c7491..187e876 100644
--- a/test/Modules/lookup.m
+++ b/test/Modules/lookup.m
@@ -1,8 +1,8 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -emit-module -x objective-c -fmodule-name=lookup_left_objc %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -emit-module -x objective-c -fmodule-name=lookup_right_objc %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -verify %s
-// RUN: %clang_cc1 -fmodules -ast-print -x objective-c -fmodules-cache-path=%t %s | FileCheck -check-prefix=CHECK-PRINT %s
+// RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -I %S/Inputs -verify %s
+// RUN: %clang_cc1 -fmodules -ast-print -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix=CHECK-PRINT %s
 
 @import lookup_left_objc;
 @import lookup_right_objc;
diff --git a/test/Modules/macro-undef-through-pch.m b/test/Modules/macro-undef-through-pch.m
new file mode 100644
index 0000000..ff0736c
--- /dev/null
+++ b/test/Modules/macro-undef-through-pch.m
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x objective-c-header -fmodules -fmodules-cache-path=%t \
+// RUN:            -I%S/Inputs/macro-undef-through-pch -emit-pch \
+// RUN:            %S/Inputs/macro-undef-through-pch/foo.h -o %t.pch
+// RUN: %clang_cc1 -x objective-c -fmodules -fmodules-cache-path=%t -include-pch %t.pch %s
+
+// PR19215
+#undef AB
diff --git a/test/Modules/macros.c b/test/Modules/macros.c
index 541c95b..7a7e570 100644
--- a/test/Modules/macros.c
+++ b/test/Modules/macros.c
@@ -3,18 +3,16 @@
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_left %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_right %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t %s
-// RUN: not %clang_cc1 -E -fmodules -x objective-c -fmodules-cache-path=%t %s | FileCheck -check-prefix CHECK-PREPROCESSED %s
+// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s
+// RUN: not %clang_cc1 -E -fmodules -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s | FileCheck -check-prefix CHECK-PREPROCESSED %s
 // FIXME: When we have a syntax for modules in C, use that.
 // These notes come from headers in modules, and are bogus.
 
 // FIXME: expected-note@Inputs/macros_left.h:11{{previous definition is here}}
 // FIXME: expected-note@Inputs/macros_right.h:12{{previous definition is here}}
 // expected-note@Inputs/macros_right.h:12{{expanding this definition of 'LEFT_RIGHT_DIFFERENT'}}
-// expected-note@Inputs/macros_top.h:13{{other definition of 'TOP_RIGHT_REDEF'}}
 // expected-note@Inputs/macros_right.h:13{{expanding this definition of 'LEFT_RIGHT_DIFFERENT2'}}
 // expected-note@Inputs/macros_left.h:14{{other definition of 'LEFT_RIGHT_DIFFERENT'}}
-// expected-note@Inputs/macros_right.h:17{{expanding this definition of 'TOP_RIGHT_REDEF'}}
 
 @import macros;
 
@@ -79,8 +77,8 @@
 #  error TOP should be visible
 #endif
 
-#ifndef TOP_LEFT_UNDEF
-#  error TOP_LEFT_UNDEF should still be defined
+#ifdef TOP_LEFT_UNDEF
+#  error TOP_LEFT_UNDEF should not be defined
 #endif
 
 void test1() {
@@ -112,7 +110,7 @@
   int i;
   float f;
   double d;
-  TOP_RIGHT_REDEF *fp = &f; // expected-warning{{ambiguous expansion of macro 'TOP_RIGHT_REDEF'}}
+  TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition
   
   LEFT_RIGHT_IDENTICAL *ip = &i;
   LEFT_RIGHT_DIFFERENT *ip2 = &i; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}}
@@ -134,6 +132,33 @@
 
 @import macros_right.undef;
 
-#ifndef TOP_RIGHT_UNDEF
-# error TOP_RIGHT_UNDEF should still be defined
+// FIXME: When macros_right.undef is built, macros_top is visible because
+// the state from building macros_right leaks through, so macros_right.undef
+// undefines macros_top's macro.
+#ifdef TOP_RIGHT_UNDEF
+# error TOP_RIGHT_UNDEF should not be defined
 #endif
+
+@import macros_other;
+
+#ifndef TOP_OTHER_UNDEF1
+# error TOP_OTHER_UNDEF1 should still be defined
+#endif
+
+#ifndef TOP_OTHER_UNDEF2
+# error TOP_OTHER_UNDEF2 should still be defined
+#endif
+
+#ifndef TOP_OTHER_REDEF1
+# error TOP_OTHER_REDEF1 should still be defined
+#endif
+int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}}
+// expected-note@macros_top.h:19 {{expanding this definition}}
+// expected-note@macros_other.h:4 {{other definition}}
+
+#ifndef TOP_OTHER_REDEF2
+# error TOP_OTHER_REDEF2 should still be defined
+#endif
+int n2 = TOP_OTHER_REDEF2; // ok
+
+int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok
diff --git a/test/Modules/macros2.c b/test/Modules/macros2.c
new file mode 100644
index 0000000..c4c8059
--- /dev/null
+++ b/test/Modules/macros2.c
@@ -0,0 +1,83 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_top %S/Inputs/module.map
+// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_left %S/Inputs/module.map
+// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros_right %S/Inputs/module.map
+// RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodules-cache-path=%t -fmodule-name=macros %S/Inputs/module.map
+// RUN: %clang_cc1 -fmodules -x objective-c -verify -fmodules-cache-path=%t -I %S/Inputs %s
+
+// This test checks some of the same things as macros.c, but imports modules in
+// a different order.
+
+@import macros_other;
+
+int n0 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok
+
+@import macros_top;
+
+TOP_OTHER_DEF_RIGHT_UNDEF *n0b; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_DEF_RIGHT_UNDEF'}}
+// expected-note@macros_top.h:22 {{expanding this definition of 'TOP_OTHER_DEF_RIGHT_UNDEF'}}
+// expected-note@macros_other.h:6 {{other definition of 'TOP_OTHER_DEF_RIGHT_UNDEF'}}
+
+@import macros_right;
+@import macros_left;
+
+#ifdef TOP_LEFT_UNDEF
+#  error TOP_LEFT_UNDEF should not be defined
+#endif
+
+#ifndef TOP_RIGHT_UNDEF
+#  error TOP_RIGHT_UNDEF should still be defined
+#endif
+
+void test() {
+  float f;
+  TOP_RIGHT_REDEF *fp = &f; // ok, right's definition overrides top's definition
+
+  // Note, left's definition wins here, whereas right's definition wins in
+  // macros.c.
+  int i;
+  LEFT_RIGHT_IDENTICAL *ip = &i;
+  LEFT_RIGHT_DIFFERENT *ip2 = &f; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT'}}
+  // expected-note@macros_left.h:14 {{expanding this}}
+  // expected-note@macros_right.h:12 {{other}}
+  LEFT_RIGHT_DIFFERENT2 *ip3 = &f; // expected-warning{{ambiguous expansion of macro 'LEFT_RIGHT_DIFFERENT2}}
+  // expected-note@macros_left.h:11 {{expanding this}}
+  // expected-note@macros_right.h:13 {{other}}
+#undef LEFT_RIGHT_DIFFERENT3
+  int LEFT_RIGHT_DIFFERENT3;
+}
+
+@import macros_right.undef;
+
+// FIXME: See macros.c.
+#ifdef TOP_RIGHT_UNDEF
+# error TOP_RIGHT_UNDEF should not be defined
+#endif
+
+#ifndef TOP_OTHER_UNDEF1
+# error TOP_OTHER_UNDEF1 should still be defined
+#endif
+
+#ifndef TOP_OTHER_UNDEF2
+# error TOP_OTHER_UNDEF2 should still be defined
+#endif
+
+#ifndef TOP_OTHER_REDEF1
+# error TOP_OTHER_REDEF1 should still be defined
+#endif
+int n1 = TOP_OTHER_REDEF1; // expected-warning{{ambiguous expansion of macro 'TOP_OTHER_REDEF1'}}
+// expected-note@macros_top.h:19 {{expanding this definition}}
+// expected-note@macros_other.h:4 {{other definition}}
+
+#ifndef TOP_OTHER_REDEF2
+# error TOP_OTHER_REDEF2 should still be defined
+#endif
+int n2 = TOP_OTHER_REDEF2; // ok
+
+int n3 = TOP_OTHER_DEF_RIGHT_UNDEF; // ok
+
+int top_redef_in_submodules = TOP_REDEF_IN_SUBMODULES;
+@import macros_top.c;
+void test2() {
+  int TOP_REDEF_IN_SUBMODULES = top_redef_in_submodules;
+}
diff --git a/test/Modules/malformed.cpp b/test/Modules/malformed.cpp
new file mode 100644
index 0000000..cd7b334
--- /dev/null
+++ b/test/Modules/malformed.cpp
@@ -0,0 +1,23 @@
+// RUN: rm -rf %t
+// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs/malformed -DHEADER="a1.h" %s 2>&1 | FileCheck %s --check-prefix=CHECK-A
+// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs/malformed -DHEADER="b1.h" %s 2>&1 | FileCheck %s --check-prefix=CHECK-B
+
+#define STR2(x) #x
+#define STR(x) STR2(x)
+#include STR(HEADER)
+
+// CHECK-A: While building module 'malformed_a'
+// CHECK-A: a1.h:1:{{.*}} error: expected '}'
+// CHECK-A: a1.h:1:{{.*}} note: to match this '{'
+//
+// CHECK-A: While building module 'malformed_a'
+// CHECK-A: a2.h:1:{{.*}} error: extraneous closing brace
+
+// CHECK-B: While building module 'malformed_b'
+// CHECK-B: b1.h:2:{{.*}} error: expected '}'
+// CHECK-B: b1.h:1:{{.*}} note: to match this '{'
+// CHECK-B: b1.h:3:{{.*}} error: extraneous closing brace ('}')
+//
+// CHECK-B: While building module 'malformed_b'
+// CHECK-B: b2.h:1:{{.*}} error: redefinition of 'g'
+// CHECK-B: b2.h:1:{{.*}} note: previous definition is here
diff --git a/test/Modules/module-private.cpp b/test/Modules/module-private.cpp
index 438dcab..9213a0f 100644
--- a/test/Modules/module-private.cpp
+++ b/test/Modules/module-private.cpp
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_left -emit-module %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_right -emit-module %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t %s -verify
+// RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s -verify
 // FIXME: When we have a syntax for modules in C++, use that.
 
 @import module_private_left;
diff --git a/test/Modules/module_file_info.m b/test/Modules/module_file_info.m
index 09319d6..f9a35ba 100644
--- a/test/Modules/module_file_info.m
+++ b/test/Modules/module_file_info.m
@@ -16,7 +16,6 @@
 // CHECK:     Triple:
 // CHECK:     CPU: 
 // CHECK:     ABI: 
-// CHECK:     C++ ABI: 
 // CHECK:     Linker version: 
 
 // CHECK: Header search options:
diff --git a/test/Modules/modulemap-locations.m b/test/Modules/modulemap-locations.m
new file mode 100644
index 0000000..9acdcd6
--- /dev/null
+++ b/test/Modules/modulemap-locations.m
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t 
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs/ModuleMapLocations/Module_ModuleMap -I %S/Inputs/ModuleMapLocations/Both -F %S/Inputs/ModuleMapLocations -x objective-c -fsyntax-only %s -verify
+
+// regular
+@import module_modulemap;
+@import both;
+// framework
+@import Module_ModuleMap_F;
+@import Module_ModuleMap_F.Private;
+@import Both_F;
+@import Inferred;
+
+void test() {
+  will_be_found1();
+  wont_be_found1(); // expected-warning{{implicit declaration of function 'wont_be_found1' is invalid in C99}}
+  will_be_found2();
+  wont_be_found2(); // expected-warning{{implicit declaration of function 'wont_be_found2' is invalid in C99}}
+}
diff --git a/test/Modules/namespaces.cpp b/test/Modules/namespaces.cpp
index 8c225e0..a6f4c25 100644
--- a/test/Modules/namespaces.cpp
+++ b/test/Modules/namespaces.cpp
@@ -36,6 +36,9 @@
   double &dr3 = global(1.0);
   double &dr4 = ::global2(1.0);
   double &dr5 = LookupBeforeImport::f(1.0);
+
+  struct AddAndReexportBeforeImport::S s;
+  int k = AddAndReexportBeforeImport::S;
 }
 
 // Test namespaces merged without a common first declaration.
@@ -69,8 +72,8 @@
 // Test merging when using anonymous namespaces, which does not
 // actually perform any merging.
 void testAnonymousNotMerged() {
-  N11::consumeFoo(N11::getFoo()); // expected-error{{cannot initialize a parameter of type 'N11::<anonymous>::Foo *' with an rvalue of type 'N11::<anonymous>::Foo *'}}
-  N12::consumeFoo(N12::getFoo()); // expected-error{{cannot initialize a parameter of type 'N12::<anonymous>::Foo *' with an rvalue of type 'N12::<anonymous>::Foo *'}}  
+  N11::consumeFoo(N11::getFoo()); // expected-error{{cannot initialize a parameter of type 'N11::(anonymous namespace)::Foo *' with an rvalue of type 'N11::(anonymous namespace)::Foo *'}}
+  N12::consumeFoo(N12::getFoo()); // expected-error{{cannot initialize a parameter of type 'N12::(anonymous namespace)::Foo *' with an rvalue of type 'N12::(anonymous namespace)::Foo *'}}
 }
 
 // expected-note@Inputs/namespaces-right.h:60 {{passing argument to parameter here}}
diff --git a/test/Modules/objc-categories.m b/test/Modules/objc-categories.m
index f08b13a..a66ab8d 100644
--- a/test/Modules/objc-categories.m
+++ b/test/Modules/objc-categories.m
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c -fmodule-name=category_right -emit-module %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c -fmodule-name=category_bottom -emit-module %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c -fmodule-name=category_other -emit-module %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t %s -verify
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify
 
 @import category_bottom;
 
diff --git a/test/Modules/objc_redef.m b/test/Modules/objc_redef.m
index f911241..28e4766 100644
--- a/test/Modules/objc_redef.m
+++ b/test/Modules/objc_redef.m
@@ -8,6 +8,6 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -emit-module -fmodule-name=redeclarations_left %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -emit-module -fmodule-name=weird_objc %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t %s -verify
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify
 // expected-no-diagnostics
 
diff --git a/test/Modules/recursive.c b/test/Modules/recursive.c
new file mode 100644
index 0000000..5315b10
--- /dev/null
+++ b/test/Modules/recursive.c
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: not %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s 2>&1 | FileCheck %s
+#include "recursive1.h"
+
+// RUN: rm -rf %t
+// RUN: not %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -emit-module -fmodule-name=recursive1 %S/Inputs/module.map 2>&1 | FileCheck %s
+
+// CHECK:      While building module 'recursive1'{{( imported from .*[/\]recursive.c:3)?}}:
+// CHECK-NEXT: While building module 'recursive2' imported from {{.*Inputs[/\]}}recursive1.h:1:
+// CHECK-NEXT: In file included from <module-includes>:1:
+// CHECK-NEXT: recursive2.h:1:10: fatal error: cyclic dependency in module 'recursive1': recursive1 -> recursive2 -> recursive1
diff --git a/test/Modules/redecl-namespaces.mm b/test/Modules/redecl-namespaces.mm
index 93102c0..203daa9 100644
--- a/test/Modules/redecl-namespaces.mm
+++ b/test/Modules/redecl-namespaces.mm
@@ -10,4 +10,4 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -emit-module -fmodule-name=redecl_namespaces_left %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -emit-module -fmodule-name=redecl_namespaces_right %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -w %s -verify
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs -w %s -verify
diff --git a/test/Modules/redeclarations.m b/test/Modules/redeclarations.m
index f210f37..11aca75 100644
--- a/test/Modules/redeclarations.m
+++ b/test/Modules/redeclarations.m
@@ -7,6 +7,6 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -emit-module -fmodule-name=redeclarations_left %S/Inputs/module.map
 // RUN: %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -emit-module -fmodule-name=redeclarations_right %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t %s -verify
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify
 // expected-no-diagnostics
 
diff --git a/test/Modules/redecls/main.m b/test/Modules/redecls/main.m
index 9ec02b0..8236092 100644
--- a/test/Modules/redecls/main.m
+++ b/test/Modules/redecls/main.m
@@ -1,8 +1,8 @@
 // RUN: rm -rf %t.mcp
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-name=a %S/module.map -fmodules-cache-path=%t.mcp
 // RUN: %clang_cc1 -fmodules -x objective-c -emit-module -fmodule-name=b %S/module.map -fmodules-cache-path=%t.mcp
-// RUN: %clang_cc1 -fmodules %s -emit-pch -o %t1.pch -fmodules-cache-path=%t.mcp
-// RUN: %clang_cc1 -fmodules %s -emit-pch -o %t2.pch -include-pch %t1.pch -fmodules-cache-path=%t.mcp
+// RUN: %clang_cc1 -fmodules %s -emit-pch -o %t1.pch -fmodules-cache-path=%t.mcp -I %S
+// RUN: %clang_cc1 -fmodules %s -emit-pch -o %t2.pch -include-pch %t1.pch -fmodules-cache-path=%t.mcp -I %S
 // RUN: %clang_cc1 -fmodules %s -fsyntax-only -include-pch %t2.pch -fmodules-cache-path=%t.mcp -verify
 
 #ifndef HEADER1
diff --git a/test/Modules/renamed.m b/test/Modules/renamed.m
index 4e8f532..ec2616e 100644
--- a/test/Modules/renamed.m
+++ b/test/Modules/renamed.m
@@ -3,6 +3,6 @@
 int f() { return same_api; }
 
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -I %S/Inputs -fmodules-cache-path=%t %s -verify
+// RUN: %clang_cc1 -fmodules -I %S/Inputs/oldname -fmodules-cache-path=%t %s -verify
 
 // expected-no-diagnostics
diff --git a/test/Modules/string_names.cpp b/test/Modules/string_names.cpp
new file mode 100644
index 0000000..ed65aa8
--- /dev/null
+++ b/test/Modules/string_names.cpp
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fmodules-decluse -I %S/Inputs/string_names %s -fmodule-name="my/module-a" -verify
+
+#include "a.h"
+#include "b.h" // expected-error {{does not depend on a module exporting}}
+#include "c.h"
diff --git a/test/Modules/subframework-from-intermediate-path.m b/test/Modules/subframework-from-intermediate-path.m
new file mode 100644
index 0000000..ae0bd64
--- /dev/null
+++ b/test/Modules/subframework-from-intermediate-path.m
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -F %S/Inputs -F %S/Inputs/DependsOnModule.framework/Frameworks %s -verify
+
+@import DependsOnModule;
+@import SubFramework; // expected-error{{module 'SubFramework' not found}}
diff --git a/test/Modules/submodules.cpp b/test/Modules/submodules.cpp
index 9c62389..a18138c 100644
--- a/test/Modules/submodules.cpp
+++ b/test/Modules/submodules.cpp
@@ -31,6 +31,9 @@
 extern MyTypeA import_self_test_a; // expected-error {{must be imported from module 'import_self.a'}}
 // expected-note@import-self-a.h:1 {{here}}
 extern MyTypeC import_self_test_c;
-// FIXME: This should be valid; import_self.b re-exports import_self.d.
-extern MyTypeD import_self_test_d; // expected-error {{must be imported from module 'import_self.d'}}
-// expected-note@import-self-d.h:1 {{here}}
+extern MyTypeD import_self_test_d;
+
+// expected-error@Inputs/submodules/module.map:15{{header 'missing.h' not found}}
+@import missing_headers.missing;
+@import missing_headers.not_missing;
+void f() { NotMissingFunction(); };
diff --git a/test/Modules/template-specialization-visibility.cpp b/test/Modules/template-specialization-visibility.cpp
new file mode 100644
index 0000000..cc11a17
--- /dev/null
+++ b/test/Modules/template-specialization-visibility.cpp
@@ -0,0 +1,43 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/template-specialization-visibility -std=c++11 %s
+//
+// FIXME: We should accept the explicit instantiation cases below too.
+// Note, errors trigger implicit imports, so only enable one error at a time.
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/template-specialization-visibility -std=c++11 -DERR1 %s
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/template-specialization-visibility -std=c++11 -DERR2 %s
+// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/template-specialization-visibility -std=c++11 -DERR3 %s
+
+#include "c.h"
+
+S<int> implicit_inst_class_template;
+int k1 = implicit_inst_class_template.n;
+
+#ifdef ERR1
+S<char> explicit_inst_class_template; // expected-error {{must be imported from module 'tsv.e'}}
+// expected-note@e.h:4 {{previous}}
+int k2 = explicit_inst_class_template.n;
+#endif
+
+#include "a.h"
+
+T<int>::S implicit_inst_member_class_template;
+int k3 = implicit_inst_member_class_template.n;
+
+#ifdef ERR2
+T<char>::S explicit_inst_member_class_template; // expected-error {{must be imported from module 'tsv.e'}}
+// expected-note@e.h:5 {{previous}}
+int k4 = explicit_inst_member_class_template.n;
+#endif
+
+T<int>::E implicit_inst_member_enum_template;
+int k5 = decltype(implicit_inst_member_enum_template)::e;
+
+#ifdef ERR3
+T<char>::E explicit_inst_member_enum_template; // expected-error {{must be imported from module 'tsv.e'}}
+// expected-note@e.h:5 {{previous}}
+int k6 = decltype(explicit_inst_member_enum_template)::e;
+#endif
+
+#if ERR1 + ERR2 + ERR3 == 0
+// expected-no-diagnostics
+#endif
diff --git a/test/Modules/unnecessary-module-map-parsing.c b/test/Modules/unnecessary-module-map-parsing.c
new file mode 100644
index 0000000..4c83448
--- /dev/null
+++ b/test/Modules/unnecessary-module-map-parsing.c
@@ -0,0 +1,8 @@
+// This checks that we are not parsing module maps if modules are not enabled.
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs/unnecessary-module-map-parsing -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -I %S/Inputs/unnecessary-module-map-parsing -fsyntax-only %s
+
+// CHECK: error: expected umbrella, header, submodule, or module export
+
+#include "a1.h"
diff --git a/test/Modules/update-after-load.cpp b/test/Modules/update-after-load.cpp
new file mode 100644
index 0000000..f497ea4
--- /dev/null
+++ b/test/Modules/update-after-load.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -I %S/Inputs/update-after-load -verify -fmodules-cache-path=%t %s
+
+// expected-no-diagnostics
+#include "a.h"
+namespace llvm {}
+#include "b.h"
+void llvm::f() {}
diff --git a/test/Modules/validate-system-headers.m b/test/Modules/validate-system-headers.m
new file mode 100644
index 0000000..9fb2bd2
--- /dev/null
+++ b/test/Modules/validate-system-headers.m
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t/ModuleCache
+// RUN: mkdir -p %t/Inputs/usr/include
+// RUN: touch %t/Inputs/usr/include/foo.h
+// RUN: echo 'module Foo [system] { header "foo.h" }' > %t/Inputs/usr/include/module.map
+
+////
+// Build a module using a system header
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -isysroot %t/Inputs -fmodules -fmodules-cache-path=%t/ModuleCache -fdisable-module-hash -x objective-c-header -fsyntax-only %s
+// RUN: cp %t/ModuleCache/Foo.pcm %t/Foo.pcm.saved
+
+////
+// Modify the system header, and confirm that we don't notice without -fmodules-validate-system-headers.
+// The pcm file in the cache should fail to validate.
+// RUN: echo ' ' >> %t/Inputs/usr/include/foo.h
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -isysroot %t/Inputs -fmodules -fmodules-cache-path=%t/ModuleCache -fdisable-module-hash -x objective-c-header -fsyntax-only %s
+// RUN: diff %t/ModuleCache/Foo.pcm %t/Foo.pcm.saved
+
+////
+// Now make sure we rebuild the module when -fmodules-validate-system-headers is set.
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -isysroot %t/Inputs -fmodules -fmodules-validate-system-headers -fmodules-cache-path=%t/ModuleCache -fdisable-module-hash -x objective-c-header -fsyntax-only %s
+// RUN: not diff %t/ModuleCache/Foo.pcm %t/Foo.pcm.saved
+
+// REQUIRES: shell
+
+@import Foo;