Index: lib/Frontend/InitHeaderSearch.cpp
===================================================================
--- lib/Frontend/InitHeaderSearch.cpp	(revision 79237)
+++ lib/Frontend/InitHeaderSearch.cpp	(working copy)
@@ -107,18 +107,60 @@
   // FIXME: get these from the target?
 
 #ifdef LLVM_ON_WIN32
-  if (Lang.CPlusPlus) {
-    // Mingw32 GCC version 4
-    AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++",
-            System, true, false, false);
-    AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/mingw32",
-            System, true, false, false);
-    AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/backward",
-            System, true, false, false);
+
+#if defined(_MSC_VER)
+  const char* vs90comntools = getenv("VS90COMNTOOLS");
+  const char* vs80comntools = getenv("VS80COMNTOOLS");
+  const char* vscomntools = NULL;
+    // If we have both vc80 and vc90, pick version we were compiled with. 
+  if (vs90comntools && vs80comntools) {
+    #if (_MSC_VER >= 1500)  // VC90
+        vscomntools = vs90comntools;
+    #elif (_MSC_VER == 1400) // VC80
+        vscomntools = vs80comntools;
+    #else
+        vscomntools = vs90comntools;
+    #endif
   }
+  else if (vs90comntools)
+    vscomntools = vs90comntools;
+  else if (vs80comntools)
+    vscomntools = vs80comntools;
+  if (vscomntools) {
+    char path[512];
+    const char* ep = strstr(vscomntools, "Common7\\Tools");
+    if (!ep)
+      ep = vscomntools + strlen(vscomntools);
+    size_t len = ep - vscomntools;
+    if ((len + 12) <= sizeof(path)) {
+      memcpy(path, vscomntools, len);
+      if ((path[len - 1] != '\\') && (path[len - 1] != '/'))
+        path[len++] = '\\';
+      strcpy(path + len, "VC\\include");
+      AddPath(path, System, false, false, false);
+    }
+    else
+      fprintf(stderr, "VS80COMNTOOLS or VS90COMNTOOLS environment variable "
+        "value is too long (%d bytes).\n", len);
+  }
+  else { // Perhaps we're not seeing environment variables.
+      // Default install paths.
+    AddPath("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\INCLUDE",
+      System, false, false, false);
+    AddPath("C:\\Program Files\\Microsoft Visual Studio 8\\VC\\include",
+      System, false, false, false);
+      // For some clang developers.
+    AddPath("G:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\INCLUDE",
+      System, false, false, false);
+  }
+#elif defined(__CYGWIN__)
+    AddPath("/usr/include", System, false, false, false);
+    AddPath("C:\\cygwin\\usr\\include", System, false, false, false);
+#else
+    AddPath("/usr/include", System, false, false, false);
+    AddPath("C:\\MinGW\\include", System, false, false, false);
+#endif
 
-  // Mingw32 GCC version 4
-  AddPath("C:/mingw/include", System, false, false, false);
 #else
 
   if (Lang.CPlusPlus) {
