When an error occurs while building a module on demand, provide "While
building module 'Foo' imported from..." notes (the same we we provide
"In file included from..." notes) in the diagnostic, so that we know
how this module got included in the first place. This is part of
<rdar://problem/12696425>.

llvm-svn: 169021
diff --git a/clang/test/Modules/build-fail-notes.m b/clang/test/Modules/build-fail-notes.m
new file mode 100644
index 0000000..fe55223
--- /dev/null
+++ b/clang/test/Modules/build-fail-notes.m
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodule-cache-path %t -fmodules -F %S/Inputs -DgetModuleVersion="epic fail" %s 2>&1 | FileCheck %s
+
+@__experimental_modules_import DependsOnModule;
+
+// CHECK: While building module 'DependsOnModule' imported from
+// CHECK: While building module 'Module' imported from
+// CHECK: error: expected ';' after top level declarator
+// CHECK: note: expanded from macro 'getModuleVersion'
+// CHECK: fatal error: could not build module 'Module'
+// CHECK: fatal error: could not build module 'DependsOnModule'
+// CHECK-NOT: error:
diff --git a/clang/test/Modules/cycles.c b/clang/test/Modules/cycles.c
index 256f118..5fcb41e 100644
--- a/clang/test/Modules/cycles.c
+++ b/clang/test/Modules/cycles.c
@@ -3,10 +3,11 @@
 // FIXME: When we have a syntax for modules in C, use that.
 @__experimental_modules_import MutuallyRecursive1;
 
-// FIXME: Lots of redundant diagnostics here, because the preprocessor
-// can't currently tell the parser not to try to load the module again.
-
+// CHECK: While building module 'MutuallyRecursive1' imported from
+// CHECK: While building module 'MutuallyRecursive2' imported from
 // CHECK: MutuallyRecursive2.h:3:32: fatal error: cyclic dependency in module 'MutuallyRecursive1': MutuallyRecursive1 -> MutuallyRecursive2 -> MutuallyRecursive1
+// CHECK: While building module 'MutuallyRecursive1' imported from
 // CHECK: MutuallyRecursive1.h:2:32: fatal error: could not build module 'MutuallyRecursive2'
 // CHECK: cycles.c:4:32: fatal error: could not build module 'MutuallyRecursive1'
+// CHECK-NOT: error:
 
diff --git a/clang/test/Modules/epic-fail.m b/clang/test/Modules/epic-fail.m
index 7d2cdcf..32ac52d 100644
--- a/clang/test/Modules/epic-fail.m
+++ b/clang/test/Modules/epic-fail.m
@@ -4,8 +4,10 @@
 @__experimental_modules_import Module;
 @__experimental_modules_import DependsOnModule;
 
+// CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
 // CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
+// CHECK: While building module 'DependsOnModule' imported from
 // CHECK: fatal error: could not build module 'Module'
 // CHECK-NOT: error: