Index: lib/Frontend/InitHeaderSearch.cpp
===================================================================
--- lib/Frontend/InitHeaderSearch.cpp	(revision 83600)
+++ lib/Frontend/InitHeaderSearch.cpp	(working copy)
@@ -66,7 +66,8 @@
     if (const FileEntry *FE = FM.getFile(MappedPath.str())) {
       if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
         // It is a headermap, add it to the search path.
-        IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied));
+        IncludeGroup[Group].push_back(
+          DirectoryLookup(HM, Type,isUserSupplied));
         return;
       }
     }
@@ -105,16 +106,13 @@
     AddPath(base + "/backward", System, true, false, false);
 }
 
+  // FIXME: This probably should goto to some platform utils place.
 #if defined(LLVM_ON_WIN32)
+#define WIN32_LEAN_AND_MEAN 1
+#include <windows.h>
 
-#if 0 // Yikes!  Can't include windows.h.
-  #if LLVM_ON_WIN32
-    #define WIN32_LEAN_AND_MEAN 1
-    #include <windows.h>
-  #endif
-
-  // Read Windows registry string.
-bool getWindowsRegistryString(const char *keyPath, const char *valueName,
+  // Read registry string.
+bool getSystemRegistryString(const char *keyPath, const char *valueName,
                        char *value, size_t maxLength) {
   HKEY hRootKey = NULL;
   HKEY hKey = NULL;
@@ -142,85 +140,95 @@
     return(false);
   long lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey);
   if (lResult == ERROR_SUCCESS) {
-    lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, (LPBYTE)value,
-                              &valueSize);
+    lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
+      (LPBYTE)value, &valueSize);
     if (lResult == ERROR_SUCCESS)
       returnValue = true;
-    RegCloseKey(kKey);
+    RegCloseKey(hKey);
   }
   return(returnValue);
 }
+#else // LLVM_ON_WIN32
+  // Read registry string.
+bool getSystemRegistryString(const char *keyPath, const char *valueName,
+                       char *value, size_t maxLength) {
+  (void)keyPath;
+  (void)valueName;
+  (void)value;
+  (void)maxLength;
+  return(false);
+}
+#endif // LLVM_ON_WIN32
 
   // Get Visual Studio installation directory.
 bool getVisualStudioDir(std::string &path) {
-  char vs80comntools[256];
-  char vs90comntools[256];
-  const char* vscomntools = NULL;
-  bool has80 = getWindowsRegistryString(
+  // Try the Windows registry first.
+  char vs80IDEInstallDir[256];
+  char vs90IDEInstallDir[256];
+  const char* vsIDEInstallDir = NULL;
+  bool has80 = getSystemRegistryString(
     "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0",
-    "InstallDir", vs80comntools, sizeof(vs80comntools) - 1);
-  bool has90 = getWindowsRegistryString(
+    "InstallDir", vs80IDEInstallDir, sizeof(vs80IDEInstallDir) - 1);
+  bool has90 = getSystemRegistryString(
     "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0",
-    "InstallDir", vs90comntools, sizeof(vs90comntools) - 1);
+    "InstallDir", vs90IDEInstallDir, sizeof(vs90IDEInstallDir) - 1);
     // If we have both vc80 and vc90, pick version we were compiled with. 
   if (has80 && has90) {
     #ifdef _MSC_VER
       #if (_MSC_VER >= 1500)  // VC90
-          vscomntools = vs90comntools;
+          vsIDEInstallDir = vs90IDEInstallDir;
       #elif (_MSC_VER == 1400) // VC80
-          vscomntools = vs80comntools;
+          vsIDEInstallDir = vs80IDEInstallDir;
       #else
-          vscomntools = vs90comntools;
+          vsIDEInstallDir = vs90IDEInstallDir;
       #endif
     #else
-      vscomntools = vs90comntools;
+      vsIDEInstallDir = vs90IDEInstallDir;
     #endif
   }
   else if (has90)
-    vscomntools = vs90comntools;
+    vsIDEInstallDir = vs90IDEInstallDir;
   else if (has80)
-    vscomntools = vs80comntools;
-  else
-    return(false);
-  char *p = strstr(vscomntools, "\\Common7\\ide");
-  if (p)
-    *p = '\0';
-  path = vscomntools;
-  return(true);
-}
-#else
-
-  // Get Visual Studio installation directory.
-bool getVisualStudioDir(std::string &path) {
-  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
+    vsIDEInstallDir = vs80IDEInstallDir;
+  if (vsIDEInstallDir && *vsIDEInstallDir) {
+    char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE");
+    if (p)
+      *p = '\0';
+    path = vsIDEInstallDir;
+    return(true);
   }
-  else if (vs90comntools)
-    vscomntools = vs90comntools;
-  else if (vs80comntools)
-    vscomntools = vs80comntools;
-  else
-    return(false);
-  char *p = (char*)strstr(vscomntools, "\\Common7\\Tools");
-  if (p)
-    *p = '\0';
-  path = vscomntools;
-  return(true);
+  else {
+    // Try the environment.
+    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 && *vscomntools) {
+      char *p = (char*)strstr(vscomntools, "\\Common7\\Tools");
+      if (p)
+        *p = '\0';
+      path = vscomntools;
+      return(true);
+    }
+    else
+      return(false);
+  }
+  return(false);
 }
-#endif
 
-#endif // LLVM_ON_WIN32
-
 void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
                                                     llvm::Triple &triple) {
   // FIXME: temporary hack: hard-coded paths.
@@ -229,29 +237,31 @@
   switch (os) {
   case llvm::Triple::Win32:
     {
-      #if defined(_MSC_VER)
-        std::string VSDir;
-        if (getVisualStudioDir(VSDir)) {
-          VSDir += "\\VC\\include";
-          AddPath(VSDir, System, false, false, false);
-        }
-        else {
-            // 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);
-        }
-      #else
+      std::string VSDir;
+      if (getVisualStudioDir(VSDir)) {
+        AddPath(VSDir + "\\VC\\include", System, false, false, false);
+        AddPath(VSDir + "\\VC\\PlatformSDK\\Include",
+          System, false, false, false);
+      }
+      else {
           // Default install paths.
-        AddPath("/Program Files/Microsoft Visual Studio 9.0/VC/include",
+        AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
           System, false, false, false);
-        AddPath("/Program Files/Microsoft Visual Studio 8/VC/include",
+        AddPath(
+        "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
           System, false, false, false);
-      #endif
+        AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include",
+          System, false, false, false);
+        AddPath(
+        "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include",
+          System, false, false, false);
+          // For some clang developers.
+        AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include",
+          System, false, false, false);
+        AddPath(
+        "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
+          System, false, false, false);
+      }
     }
     break;
   case llvm::Triple::Cygwin:
@@ -379,8 +389,8 @@
 }
 
 
-/// RemoveDuplicates - If there are duplicate directory entries in the specified
-/// search list, remove the later (dead) ones.
+/// RemoveDuplicates - If there are duplicate directory entries in the
+/// specified search list, remove the later (dead) ones.
 static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
                              bool Verbose) {
   llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
Index: lib/Frontend/CMakeLists.txt
===================================================================
--- lib/Frontend/CMakeLists.txt	(revision 83600)
+++ lib/Frontend/CMakeLists.txt	(working copy)
@@ -1,6 +1,6 @@
 set(LLVM_NO_RTTI 1)
 
-add_clang_library(clangFrontend
+add_clang_library_not_ANSI(clangFrontend
   ASTConsumers.cpp
   ASTUnit.cpp
   AnalysisConsumer.cpp
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 83600)
+++ CMakeLists.txt	(working copy)
@@ -65,6 +65,44 @@
     ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
 endmacro(add_clang_library)
 
+# This is a hack so that some projects can be build without
+# MSVC's /Za (strict ANSI) option.
+macro(add_clang_library_not_ANSI name)
+  set(srcs ${ARGN})
+  if(MSVC_IDE OR XCODE)
+    file( GLOB_RECURSE headers *.h *.td *.def)
+    set(srcs ${srcs} ${headers})
+    string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
+    list( GET split_path -1 dir)
+    file( GLOB_RECURSE headers 
+      ../../include/clang${dir}/*.h
+      ../../include/clang${dir}/*.td
+      ../../include/clang${dir}/*.def)
+    set(srcs ${srcs} ${headers})
+  endif(MSVC_IDE OR XCODE)
+  if (SHARED_LIBRARY)
+    set(libkind SHARED)
+  else()
+    set(libkind)
+  endif()
+  add_library( ${name} ${libkind} ${srcs} )
+  if( LLVM_COMMON_DEPENDS )
+    add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
+  endif( LLVM_COMMON_DEPENDS )
+  if( LLVM_LINK_COMPONENTS )
+    llvm_config(${name} ${LLVM_LINK_COMPONENTS})
+  endif( LLVM_LINK_COMPONENTS )
+  if( LLVM_USED_LIBS )
+    foreach(lib ${LLVM_USED_LIBS})
+      target_link_libraries( ${name} ${lib} )
+    endforeach(lib)
+  endif( LLVM_USED_LIBS )
+  add_dependencies(${name} ClangDiagnosticCommon)
+  install(TARGETS ${name}
+    LIBRARY DESTINATION lib
+    ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+endmacro(add_clang_library_not_ANSI)
+
 macro(add_clang_executable name)
   set(srcs ${ARGN})
   if(MSVC_IDE)
